home *** CD-ROM | disk | FTP | other *** search
/ CD ROM Paradise Collection 4 / CD ROM Paradise Collection 4 1995 Nov.iso / win / csh_txt.zip / USERGUID.TXT
Text File  |  1994-03-15  |  681KB  |  21,377 lines

  1.                             
  2.                             
  3.                             
  4.                             
  5.                             
  6.                             
  7.                             
  8.                             
  9.                   Hamilton C shell(TM)
  10.  
  11.  
  12.  
  13.              User Guide and Reference Manual
  14.  
  15.  
  16.  
  17.  
  18.  
  19.  
  20.  
  21.  
  22.  
  23.  
  24.  
  25.                        Release 2.2
  26.  
  27.                      February, 1994
  28.  
  29.  
  30.  
  31.  
  32.  
  33.  
  34.  
  35.  
  36.  
  37.  
  38.  
  39.  
  40.  
  41.  
  42.  
  43.   Hamilton Laboratories, 13 Old Farm Road, Wayland, MA
  44.                        01778-3117
  45.         Phone 508-358-5715   +   FAX 508-358-1113
  46.     MCI Mail 389-0321   +   Internet 3890321@mcimail.com
  47.   BIX hamilton   +   CompuServe 70034,2025   +   Telex
  48.                        6503890321
  49.                             
  50.  
  51.  
  52.  
  53.  
  54.  
  55.  
  56.  
  57.  
  58.  
  59.  
  60.  
  61.  
  62.  
  63.  
  64.  
  65.  
  66.  
  67.  
  68.  
  69.  
  70.  
  71.  
  72.  
  73.  
  74.  
  75.  
  76.  
  77.  
  78.  
  79.  
  80. Copyright (c) 1988 - 1994 by Hamilton Laboratories.
  81.  
  82. All rights  reserved.  No part of this publication may be
  83. reproduced, stored in a retrieval system, or transmitted,
  84. in any  form or  by any  means,  electronic,  mechanical,
  85. photocopying, recording,  or otherwise  without the prior
  86. written permission  from Hamilton  Laboratories.  Printed
  87. in the United States of America.
  88.  
  89. AT,  PS/2   and  OS/2   are  registered   trademarks   of
  90. International Business  Machines Corporation.  Windows NT
  91. is a  trademark of  Microsoft Corporation.    UNIX  is  a
  92. registered  trademark   of  UNIX   System   Laboratories.
  93. Hamilton C shell is a trademark of Hamilton Laboratories.
  94.                
  95.  
  96.  
  97.  
  98.                                 Table of Contents
  99.  
  100.  
  101.  
  102.                  Preface .................................. v
  103.  
  104.                  License Agreement....................... vii
  105.  
  106.                  Introduction .............................  1
  107.  
  108.                  Installation Guide .......................  4
  109.                    Installation on OS/2   4
  110.                    Installation on Windows NT  16
  111.  
  112.                  Common Problems .......................... 19
  113.  
  114.                  Product Support .......................... 30
  115.  
  116.                  User Guide ............................... 33
  117.                    The Utilities     40
  118.                    I/O Redirection and Piping  57
  119.                    The History Mechanism  68
  120.                    Variables    72
  121.                    Wildcarding  81
  122.                    Editing 89
  123.                    Quoting 94
  124.                    Expressions  98
  125.                    Aliases 107
  126.                    Programming Constructs      112
  127.                    Scheduling        134
  128.                    Order of Evaluation    141
  129.                    Customizing the Shell  144
  130.                    Summary 157
  131.  
  132.                  Examples .................................159
  133.                    Factor.csh   159
  134.                    Whereis.csh       160
  135.                    Samples Directory      161
  136.  
  137.                  Compatibility Guide ......................167
  138.  
  139.                  Language Reference .......................177
  140.                    Basic Statements  177
  141.                    Condition Testing      177
  142.                    Iteration    180
  143.                    Procedures   180
  144.                    Aliases 181
  145.                    Variable and Expression Manipulation  181
  146.                    Local Variables   183
  147.                    Function Keys     184
  148.  
  149.  
  150.  
  151.                                           iii
  152.  
  153.                    Miscellaneous Statements         186
  154.                    Statement Relationships     188
  155.                    I/O Redirection   188
  156.                    Expression Operators   190
  157.                    File System Tests 192
  158.                    Special Devices   193
  159.                    Wildcarding and Pattern Matching 195
  160.                    Filename Completion    197
  161.                    Command Line Editing   199
  162.                    History Recall    202
  163.                    Command Completion     202
  164.                    Quoting 204
  165.                    Escape Sequences  204
  166.                    Variable Substitution  206
  167.                    Substitution Modifiers 207
  168.                    Pathname Editing       209
  169.  
  170.                  Predefined Variables .....................211
  171.                    Environmental Variables     211
  172.                    Process-Wide Variables 216
  173.                    Per-Thread Variables   218
  174.                    Variables, Sorted by Name   224
  175.  
  176.                  Built-in Procedures ......................236
  177.  
  178.                  Utilities ................................241
  179.  
  180.                  Popular Aliases ..........................248
  181.  
  182.                  Help Information .........................254
  183.                    Help for the shell          254
  184.                    Help for the utilities 256
  185.  
  186.  
  187.  
  188.  
  189.  
  190.  
  191.  
  192.  
  193.  
  194.  
  195.  
  196.  
  197.  
  198.  
  199.  
  200.  
  201.  
  202.  
  203.  
  204.  
  205.  
  206.  
  207.  
  208.  
  209.  
  210.                                           iv
  211.  
  212.                
  213.  
  214.  
  215.  
  216.  
  217.  
  218.  
  219.  
  220.  
  221.  
  222.             Preface
  223.  
  224.                Thank you  for purchasing  and using Hamilton C shell.
  225.             Our goal and guarantee is your satisfaction.
  226.  
  227.                Hamilton C  shell is  an advanced  command  processing
  228.             language for OS/2 and Windows NT.  It's a professionally-
  229.             oriented language  for manipulating  files, processes and
  230.             threads and  connections between  these objects.    As  a
  231.             language, it  offers  what  we  think  of  as  the  human
  232.             characteristics of  language:   a useful  vocabulary  and
  233.             grammar,  a  limitless  freedom  of  expression  and  the
  234.             ability to  describe and  relate events  in time.    Most
  235.             important, it  projects your influence into the future by
  236.             allowing you  to easily  describe you  want done  even if
  237.             what you  want is  quite complex  and dependent on future
  238.             events.
  239.  
  240.                Hamilton C  shell is  a full  implementation of  the C
  241.             shell language  popular on  engineering workstations.  It
  242.             was created  specifically for  OS/2  protected  mode  and
  243.             meticulously ported  to Windows  NT.  Not one of the more
  244.             than 113,000  lines of  code in  the current  release was
  245.             created on or ported from anything but OS/2 or NT.
  246.  
  247.                This product  complies with accepted standards for the
  248.             language and  with the conventions of OS/2 and NT.  Users
  249.             with previous  experience with  the standard  OS/2, NT or
  250.             DOS command  processors or  the  original  Unix  C  shell
  251.             should   find   enough   reasonably   familiar   language
  252.             constructs and  features to  make the product immediately
  253.             productive.
  254.  
  255.  
  256.  
  257.                                Douglas A. Hamilton
  258.                              Wayland, Massachusetts
  259.                                 December 9, 1988
  260.                           (Last revised March 15, 1994)
  261.  
  262.  
  263.  
  264.  
  265.  
  266.  
  267.  
  268.  
  269.                                            v
  270.  
  271.                
  272.  
  273.  
  274.  
  275.  
  276.  
  277.  
  278.  
  279.  
  280.  
  281.  
  282.  
  283.  
  284.  
  285.  
  286.  
  287.  
  288.  
  289.  
  290.  
  291.  
  292.  
  293.  
  294.  
  295.  
  296.  
  297.  
  298.  
  299.  
  300.  
  301.  
  302.  
  303.  
  304.  
  305.  
  306.  
  307.  
  308.  
  309.  
  310.  
  311.  
  312.  
  313.  
  314.  
  315.  
  316.  
  317.  
  318.  
  319.  
  320.  
  321.  
  322.  
  323.  
  324.  
  325.  
  326.  
  327.  
  328.                                           vi
  329.  
  330. IMPORTANT -- READ CAREFULLY BEFORE OPENING.  By opening this
  331. sealed package, you indicate your acceptance of the following
  332. Hamilton Laboratories License Agreement.
  333.  
  334. Hamilton Laboratories License Agreement
  335.  
  336. This is a legal agreement between you, the end user, and Hamilton
  337. Laboratories.  By opening this sealed package, you are agreeing
  338. to be bound by the terms of this agreement.  If you do not agree
  339. to the terms of this agreement, promptly return the unopened
  340. package and any accompanying items for a full refund.
  341.  
  342.              HAMILTON LABORATORIES SOFTWARE LICENSE
  343.  
  344. 1.  GRANT OF LICENSE.  Hamilton Laboratories grants to you the
  345. right to use one copy of the enclosed Hamilton Laboratories
  346. software program (the ``SOFTWARE'') on a single terminal
  347. connected to a single computer (i.e., with a single CPU).  You
  348. may not network the SOFTWARE or otherwise use it on more than one
  349. computer or computer terminal at the same time.
  350.  
  351. 2.  COPYRIGHT.  The SOFTWARE is owned by Hamilton Laboratories or
  352. its suppliers and is protected by United States copyright laws
  353. and international treaty provisions.  Therefore, you must treat
  354. the SOFTWARE like any other copyrighted material (e.g., a book or
  355. musical recording) except that you may either (a) make a
  356. reasonable number of copies of the SOFTWARE solely for backup
  357. purposes or (b) transfer the SOFTWARE to a single hard disk
  358. provided the original and any other copies are kept solely for
  359. backup or archival purposes.  You may not copy the written
  360. materials accompanying the software.
  361.  
  362. 3.  OTHER RESTRICTIONS.  You may not rent or lease the SOFTWARE,
  363. but you may transfer the SOFTWARE and accompanying written
  364. materials on a permanent basis provided you retain no copies and
  365. the recipient agrees to the terms of this Agreement.  You may not
  366. reverse engineer, decompile or disassemble the SOFTWARE.  If
  367. SOFTWARE is an update, any transfer must include the update and
  368. all prior versions.
  369.  
  370. 4.  DUAL MEDIA SOFTWARE.  If this SOFTWARE package contains both
  371. 3 1/2'' and 5 1/4'' disks, you may use only the disks appropriate
  372. for your single-user computer.  You may not use the other disks
  373. on another computer or loan, rent, lease, or transfer them to
  374. another user except as part of the permanent transfer (as
  375. provided above) of all SOFTWARE and written materials.
  376.  
  377.                         LIMITED WARRANTY
  378.  
  379. LIMITED WARRANTY.  Hamilton Laboratories warrants that the
  380. SOFTWARE will perform substantially in accordance with the
  381. accompanying written materials for a period of 90 days from the
  382. date of purchase.  Some states do not allow limitations on the
  383. duration of an implied warranty, so the above may not apply to
  384. you.
  385. CUSTOMER REMEDIES.  Hamilton Laboratories' entire liability and
  386. your exclusive remedy shall be, at Hamilton Laboratories' option,
  387. either (a) return of the price paid or (b) repair or replacement
  388. of the SOFTWARE that does not meet this Limited Warranty and
  389. which is returned to Hamilton Laboratories with a copy of your
  390. receipt.  During the first 90 days from the date of purchase, if
  391. you determine that the SOFTWARE is unsatisfactory in any way, you
  392. may return it with proof of purchase and a written description of
  393. why the SOFTWARE was unsatisfactory for a full refund.
  394.  
  395. NO OTHER WARRANTIES.  Hamilton Laboratories disclaims all other
  396. warranties, either express or implied, including, but not limited
  397. to implied warranties of merchantability and fitness for a
  398. particular purpose, with respect to the SOFTWARE and accompanying
  399. written materials.  This limited warranty gives you specific
  400. legal rights.  You may have others, which vary from state to
  401. state.
  402.  
  403. NO LIABILITY FOR CONSEQUENTIAL DAMAGES.  In no event shall
  404. Hamilton Laboratories or its suppliers be liable for any damages
  405. whatsoever (including, without limitation, damages for loss of
  406. business profits, business interruption, loss of business
  407. information, or other pecuniary loss) arising out of the use of
  408. or inability to use this Hamilton Laboratories product, even if
  409. Hamilton Laboratories has been advised of the possibility of such
  410. damages.  Because some states do not allow the exclusion or
  411. limitation of liability for consequential or incidental damages,
  412. the above limitation may not apply to you.
  413.  
  414. This Agreement is governed by the laws of the State of
  415. Massachusetts.
  416.  
  417. Should you have any questions concerning this Agreement, or if
  418. you wish to contact Hamilton Laboratories for any reason, please
  419. write:  Hamilton Laboratories Customer Service, 13 Old Farm Road,
  420. Wayland, MA 01778-3117.
  421.  
  422.                                                                  Introduction
  423.  
  424.  
  425.             
  426.  
  427.  
  428.                               Hamilton C shell(TM)
  429.  
  430.  
  431.  
  432.  
  433.             Introduction
  434.  
  435.                Hamilton C shell is a language for interactively using
  436.             OS/2 and  Windows NT.   Compared to the standard OS/2 and
  437.             NT command  processors,  it  provides  a  vocabulary  and
  438.             grammar that  allows much  more complex  activities to be
  439.             described.  Some of its major innovations include
  440.  
  441.                +   Command line  editing of  enormous statements with
  442.                    arrow keys and filename and command completion.
  443.  
  444.                +   User-definable function keys.
  445.  
  446.                +   Fully  recursive   grammar.    Statements  can  be
  447.                    arbitrarily nested  or piped  without concern  for
  448.                    statement length or other arbitrary restrictions.
  449.  
  450.                +   Procedures and  aliases.   The vocabulary  of  the
  451.                    language is meant to be extensible by the user.
  452.  
  453.                +   Variables, arrays  and expressions.   Integer  and
  454.                    floating  point   arithmetic,   pattern   matching
  455.                    facilities  and  various  file  system  tests  and
  456.                    editing operators provide an expressive grammar.
  457.  
  458.                +   Threads  and   processes.     Child  threads   and
  459.                    processes  can   be  spawned   to   run   commands
  460.                    asynchronously or in the background.
  461.  
  462.                +   Command substitution.  The output  of one  command
  463.                    can  be  stuffed  back  on  the  command  line  as
  464.                    arguments to another.
  465.  
  466.                +   History.    Past  commands  can  be  recalled  and
  467.                    edited.
  468.  
  469.                +   Advanced filename wildcarding.
  470.  
  471.                This product  complies  fully  with  industry-accepted
  472.             definitions for  the C  shell language.   The user is not
  473.             asked to  learn yet  another new proprietary language not
  474.             available anywhere  else.    Instead,  a  tested,  proven
  475.             framework  has   been  adapted   with   modern   compiler
  476.             technology for OS/2 and NT:
  477.  
  478.  
  479.  
  480.  
  481.  
  482.                                       Page 1
  483.  
  484.      Introduction
  485.  
  486.  
  487.                1.  A  modern  top-down  parser  is  used  for  better
  488.                    language recognition and performance.
  489.  
  490.                2.  It's easier  to use.   The  syntax and grammar has
  491.                    been made  flexible and more consistent with other
  492.                    modern high level language conventions.
  493.  
  494.                3.  It knows  about OS/2  and  NT:  HPFS,  NTFS,  long
  495.                    filenames,  environmental   variables,   networks,
  496.                    international character  sets, and  about all  the
  497.                    various kinds  of applications  supported by  your
  498.                    system.  Under OS/2, it has no trouble starting PM
  499.                    and (under  OS/2 2.x)  seamless Win3.x, 32-bit and
  500.                    Virtual DOS machine (VDM) applications.  Under NT,
  501.                    it works  with all  DOS, Win3.x,  Win32, POSIX and
  502.                    OS/2 character mode applications.
  503.  
  504.                4.  You can  customize the  C shell  to  give  you  as
  505.                    little or  as much NT or OS/2 versus UNIX behavior
  506.                    as you choose.   For example, either \ or / can be
  507.                    used in  a filename.  Either - or / can be used as
  508.                    an option switch character for the utilities.  You
  509.                    can decide  whether typing  cd with no destination
  510.                    directory means  report the  current directory (NT
  511.                    or OS/2  style) or take you to the home directory,
  512.                    and so  on.   (The chapter  on customizing  the  C
  513.                    shell, beginning  on page  3, is  devoted to  this
  514.                    topic.)
  515.  
  516.                5.  Threads   are    used   extensively   to   achieve
  517.                    performance  and  functionality  not  possible  in
  518.                    UNIX.
  519.  
  520.                6.  Feedback to  the user,  especially when  reporting
  521.                    errors has  been improved.   If  you encounter  an
  522.                    error inside  a complex  script, you'll even get a
  523.                    complete dump  of the  call stack  showing how you
  524.                    got there.
  525.  
  526.  
  527.  
  528.             Who is it Designed For?
  529.  
  530.                Most  users   of  Hamilton   C  shell  are  relatively
  531.             technically oriented  computer  users.    Often,  they're
  532.             software developers.   They  have a  business need for an
  533.             OS/2 or an NT system.
  534.  
  535.                Peering over their shoulders, they typically have lots
  536.             of windows  open on  the screen.  Many of the windows are
  537.             running copies of this shell.  Some copies are transient,
  538.             created to  display with  little snippets  of information
  539.             needed on  the spur  of the  moment.  Other copies of the
  540.  
  541.  
  542.  
  543.  
  544.                                       Page 2
  545.  
  546.                                                                  Introduction
  547.  
  548.  
  549.             shell would  be used for more long-running projects:  for
  550.             example, getting a make working for a major application.
  551.  
  552.                A shell  window is  like any  other application window
  553.             but with  a different  paradigm.   Instead of  data, rows
  554.             and columns of numbers or lines of text, the object being
  555.             manipulated is the machine itself.
  556.  
  557.                A good  shell tackles  a different  problem than icons
  558.             and windows.  Instead of the point-and-shoot immediacy of
  559.             ``do this single thing now,'' a shell offers language and
  560.             the ability  to describe  more customized  or  repetitive
  561.             actions, e.g.,  identify a suitable set of files, perform
  562.             some action  against them  and filter the results in some
  563.             interesting way.
  564.  
  565.  
  566.  
  567.  
  568.  
  569.  
  570.  
  571.  
  572.  
  573.  
  574.  
  575.  
  576.  
  577.  
  578.  
  579.  
  580.  
  581.  
  582.  
  583.  
  584.  
  585.  
  586.  
  587.  
  588.  
  589.  
  590.  
  591.  
  592.  
  593.  
  594.  
  595.  
  596.  
  597.  
  598.  
  599.  
  600.  
  601.  
  602.  
  603.  
  604.  
  605.  
  606.                                       Page 3
  607.  
  608.      Installation
  609.  
  610.  
  611.             
  612.  
  613.  
  614.                                Installation Guide
  615.  
  616.  
  617.             This section outlines how to install the Hamilton C shell
  618.             on your  system.  If you are installing the OS/2 version,
  619.             follow the  instructions beginning  on  this  page.    To
  620.             install the  Windows NT  version  of  Hamilton  C  shell,
  621.             please turn to page 5.
  622.  
  623.             If  you   encounter  problems,   consult   the   ``Common
  624.             Problems'' section  on page  5 or  call us  for technical
  625.             support as described on page 5.
  626.  
  627.  
  628.  
  629.                               Installation on OS/2
  630.  
  631.  
  632.             The first  few steps, copying files from diskette to your
  633.             hard disk  and modifying your config.sys, are the same on
  634.             all releases  of OS/2.   The  remaining  steps  --  those
  635.             associated with  actually installing  Hamilton C shell on
  636.             your OS/2  desktop --  depend on  which release  of  OS/2
  637.             you're running.   We  suggest a  ``vanilla'' installation
  638.             initially, but later you may want to customize it to your
  639.             own tastes.   For  help with  that, read  the chapter  on
  640.             ``Customizing the Shell,'' beginnning on page 5.
  641.  
  642.             Once you've  gained familiarity  with both  OS/2 and with
  643.             the C  shell, you  may want  to set up the C shell as the
  644.             default command  processor for OS/2, completely replacing
  645.             cmd.exe as  described on  page 5.   The  advantage to  be
  646.             gained (except under the 6.167 Beta and LA builds of 2.0)
  647.             is that  the C  shell will then be able to change its own
  648.             title bar and icon when you run an external command.
  649.  
  650.  
  651.  
  652.             System Requirements
  653.  
  654.             Installation requires  a 286-, 386- or 486-based AT(R) or
  655.             PS/2(R) or  compatible, running OS/2(R) 1.1 (Presentation
  656.             Manager) or  Microsoft SDK 1.06 or later.  Roughly 1.2 MB
  657.             of disk space is used.
  658.  
  659.             Hamilton C shell and the utilities supplied with it fully
  660.             support HPFS  and long  filenames when running under OS/2
  661.             1.2 or  later. They  will work properly in a Presentation
  662.             Manager text window or full-screen and with networks such
  663.             as LAN  Manager or  IBM LAN Server.  If you're using OS/2
  664.             2.x, it knows how to run 32-bit applications and start up
  665.  
  666.  
  667.  
  668.                                       Page 4
  669.  
  670.                                                                  Installation
  671.  
  672.  
  673.             Multiple Virtual DOS machines and run Win3.x applications
  674.             seamlessly on  the desktop.   The  product  is  not  copy
  675.             protected.
  676.  
  677.  
  678.  
  679.             Basic Installation, Part I  (All releases of OS/2)
  680.  
  681.             1.   Copy the  executables in  the bin directory into any
  682.                  desired directory on your search PATH, so long as it
  683.                  appears  ahead   of  the  directory  containing  the
  684.                  standard  IBM/Microsoft  more.com.    (We  supply  a
  685.                  dramatically improved  more.exe, which  should  take
  686.                  precedence.)   If you're  creating a  new directory,
  687.                  remember to add it to your search PATH in config.sys
  688.                  and in the login.csh file you create next.
  689.  
  690.             2.   Edit  config.sys,   adding  statements   to   define
  691.                  whatever directory  you choose  to designate as your
  692.                  HOME directory and to ensure you're configured for a
  693.                  sufficient number of threads.    The significance of
  694.                  a home  directory is  principally that  it  will  be
  695.                  convenient to  specify pathnames  relative  to  that
  696.                  directory.   The default  number of  threads is  too
  697.                  small if  you expect  to have  lots of windows open.
  698.                  Also, be  sure your PATH explicitly lists ``.'', the
  699.                  current directory.
  700.  
  701.                  You may  also want  to include  definitions for TABS
  702.                  and  COLORS.     more.exe  and  some  of  the  other
  703.                  utilities look  for TABS  to see if you want them to
  704.                  display text  with tabs  expanded out  to  something
  705.                  other than the default of every 8 characters.
  706.  
  707.                  By default, the C shell displays white characters on
  708.                  a black  background.   The COLORS  variable lets you
  709.                  choose something  different from  this set:   black,
  710.                  red, green,  yellow, blue,  magenta (or  blue  red),
  711.                  cyan (or  blue green)  and white.  Foreground colors
  712.                  may also  be bright,  dim, blink  or reverse.    The
  713.                  keyword ``on'' introduces background colors.  (Blink
  714.                  only causes  true blinking  full-screen; in  a  text
  715.                  window,  it  just  makes  the  background  brighter.
  716.                  Also, yellow  is a  true yellow only if it's bright.
  717.                  These are  OS/2 limitations  not related  to  the  C
  718.                  shell.)   For more  information  on  setting  screen
  719.                  colors, please refer to the customization chapter or
  720.                  to the colors.csh file in the samples directory.
  721.  
  722.                  Here's  an   example  of   what  you  might  add  to
  723.                  config.sys:
  724.  
  725.                       THREADS=255
  726.                       SET HOME=D:\DOUG
  727.  
  728.  
  729.  
  730.                                       Page 5
  731.  
  732.      Installation
  733.  
  734.  
  735.                       SET TABS=3
  736.                       SET COLORS=WHITE ON BLUE
  737.  
  738.                  (Please be  sure your  config.sys file contains only
  739.                  upper-case alphabetics,  no  lower-case,  if  you're
  740.                  using OS/2  1.1.   Lower-case alphabetics were known
  741.                  to cause random OS/2 system failures in that release
  742.                  of OS/2.   This  was a  known bug in the OS/2 kernel
  743.                  and was not application dependent.)
  744.  
  745.             3.   Copy  the   login.csh  and  startup.csh  files  into
  746.                  ``home'' directory.
  747.  
  748.                  Unless you're  convinced that  you've set  all  your
  749.                  environmental variables in your config.sys (and that
  750.                  your  PATH   explicitly  lists  ``.'',  the  current
  751.                  directory), use  the  dumpenv  utility  to  paste  a
  752.                  series of  setenv statements into the login.csh file
  753.                  to recreate  the environment  you've been using with
  754.                  cmd.exe:
  755.  
  756.                       dumpenv >>login.csh
  757.  
  758.                  (To see  what dumpenv  does, look at the source code
  759.                  in the  samples  directory  or  simply  run  dumpenv
  760.                  without redirecting the output.)
  761.  
  762.                  The login.csh  and startup.csh  files can  be edited
  763.                  with any ascii editor to customize the shell to your
  764.                  needs.   The login.csh file has a lot of comments in
  765.                  it which  can take  the shell  a second  or more  to
  766.                  read; you'll almost certainly want to delete some of
  767.                  them once  you've read  them so the shell will start
  768.                  up faster.   Also,  any setenv  statements that just
  769.                  duplicate  what's   in  your   config.sys   can   be
  770.                  discarded.
  771.  
  772.                  The remaining  steps depend on which release of OS/2
  773.                  you're running.
  774.  
  775.  
  776.  
  777.             Basic Installation, Part II  (OS/2 1.1)
  778.  
  779.             4.   Add csh.exe  with the  title ``Hamilton C shell'' to
  780.                  the ``Start  Programs'' menu.  To do this, pull-down
  781.                  ``Program'' and select ``Add...'' from the menu bar.
  782.                  Fill in:
  783.  
  784.                       Program title....   Hamilton C shell
  785.                       Path and file name  ....as
  786.                       appropriate....\csh.exe
  787.                       Parameters....      -L
  788.  
  789.  
  790.  
  791.  
  792.                                       Page 6
  793.  
  794.                                                                  Installation
  795.  
  796.  
  797.                  The ``-L'' part tells csh.exe when it starts up that
  798.                  it's a  ``login'' shell,  which means it should look
  799.                  for  a   login.csh  file.   (Refer  to  page  8  for
  800.                  additional information on other options.)
  801.  
  802.             5.   You will  likely want  to create  a second entry for
  803.                  running full-screen.  It's more convenient if you're
  804.                  mostly working with applications that only run full-
  805.                  screen  or   if  you   want  faster   text  display,
  806.                  especially scrolling.   To do that, from the ``Start
  807.                  Programs'' menu,  pull-down ``Program''  and  select
  808.                  ``Copy...'' from the menu bar.  In the Copy Programs
  809.                  popup, fill  in the  following and push the ``Copy''
  810.                  button:
  811.  
  812.                       Change Title to:    Hamilton C shell -- Full
  813.                       Screen
  814.  
  815.                  Back in  the ``Start  Programs'' window,  select the
  816.                  new full  screen title,  pull-down  ``Program''  and
  817.                  select  ``Change...''.     In   the  Change  Program
  818.                  Information popup, push the ``Change'' button.  This
  819.                  brings up  the How  to Run the Program popup; select
  820.                  ``Run the program full-screen'' and ``Enter''.
  821.  
  822.             6.   All  the   material  in  the  samples  directory  is
  823.                  provided for  its tutorial value; you may or may not
  824.                  wish to copy it onto your hard disk.
  825.  
  826.             7.   Reboot your  system before starting Hamilton C shell
  827.                  for the  first time.  This causes the new statements
  828.                  in config.sys to take effect.
  829.  
  830.  
  831.  
  832.  
  833.  
  834.  
  835.  
  836.  
  837.  
  838.  
  839.  
  840.  
  841.  
  842.  
  843.  
  844.  
  845.  
  846.  
  847.  
  848.  
  849.  
  850.  
  851.  
  852.  
  853.  
  854.                                       Page 7
  855.  
  856.      Installation
  857.  
  858.  
  859.             Basic Installation, Part II  (OS/2 1.2 or 1.3)
  860.  
  861.             4.   Add csh.exe  with the  title ``Hamilton C shell'' to
  862.                  the ``Group  - Main''  menu.   To do this, pull-down
  863.                  ``Program'' and select ``New...'' from the menu bar.
  864.                  Fill in:
  865.  
  866.                       Program title:      Hamilton C shell
  867.                       Path and file name: ....as
  868.                       appropriate....\csh.exe
  869.                       Parameters:         -L
  870.  
  871.                  The ``-L'' part tells csh.exe when it starts up that
  872.                  it's a  ``login'' shell,  which means it should look
  873.                  for  a   login.csh  file.   (Refer  to  page  9  for
  874.                  additional information on other options.)
  875.  
  876.             5.   You will  likely want  to create  a second entry for
  877.                  running full-screen.  It's more convenient if you're
  878.                  mostly working with applications that only run full-
  879.                  screen  or   if  you   want  faster   text  display,
  880.                  especially scrolling.   To do that, from the ``Group
  881.                  - Main''  menu,  pull-down  ``Program''  and  select
  882.                  ``Copy...'' from the menu bar.  In the Copy Programs
  883.                  popup, fill  in the  following and push the ``Copy''
  884.                  button:
  885.  
  886.                       Change Title to:    Hamilton C shell -- Full
  887.                       Screen
  888.  
  889.                  Back in  the ``Group - Main'' window, select the new
  890.                  full screen  title, pull-down ``Program'' and select
  891.                  ``Properties...'' .   In  the Properties popup, push
  892.                  the down arrow next to the ``Program Type:'' box and
  893.                  select ``OS/2  Full Screen''  on the  list that will
  894.                  appear and then push the ``Change'' button.
  895.  
  896.             6.   All  the   material  in  the  samples  directory  is
  897.                  provided for  its tutorial value; you may or may not
  898.                  wish to copy it onto your hard disk.
  899.  
  900.             7.   Reboot your  system before starting Hamilton C shell
  901.                  for the  first time.  This causes the new statements
  902.                  in config.sys to take effect.
  903.  
  904.  
  905.  
  906.  
  907.  
  908.  
  909.  
  910.  
  911.  
  912.  
  913.  
  914.  
  915.  
  916.                                       Page 8
  917.  
  918.                                                                  Installation
  919.  
  920.  
  921.             Basic Installation, Part II  (OS/2 2.x)
  922.  
  923.             4.   Open the  Templates folder and drag a program object
  924.                  to the  desktop (or  another folder) by pressing and
  925.                  holding the  right mouse button as you drag.  On the
  926.                  Program page  of the  ``Program -  Settings'' window
  927.                  that will appear, fill in:
  928.  
  929.                       Path and file name: ....as
  930.                       appropriate....\csh.exe
  931.                       Parameters:         -L
  932.  
  933.                  The ``-L'' part tells csh.exe when it starts up that
  934.                  it's a  ``login'' shell,  which means it should look
  935.                  for  a   login.csh  file.  (Refer  to  page  10  for
  936.                  additional information on other options.)
  937.  
  938.             5.   On  the  Window  page  of  the  Settings,  you  will
  939.                  probably want to set
  940.  
  941.                       Minimized button behavior:  Minimize window to
  942.                       desktop
  943.  
  944.                       Object open behavior:  Create new window
  945.  
  946.                  Doing this will let you conveniently open up lots of
  947.                  copies of the C shell as needed.
  948.  
  949.             6.   On the General page of the Settings, set
  950.  
  951.                       Title:              Hamilton C shell
  952.  
  953.                  Close the Settings by pressing Alt-F4.
  954.  
  955.             7.   You will  likely want  to create  a second entry for
  956.                  running full-screen.  It's more convenient if you're
  957.                  mostly working with applications that only run full-
  958.                  screen  or   if  you   want  faster   text  display,
  959.                  especially scrolling.   To do that, copy the C shell
  960.                  icon you  just created  by right-clicking  on it and
  961.                  selecting   ``Copy...''   and   then   choosing   an
  962.                  appropriate   destination   folder   (probably   the
  963.                  desktop) for  the copy.   You can also copy the icon
  964.                  by pressing  and holding the Ctrl key while dragging
  965.                  with the right mouse button.
  966.  
  967.             8.   Once you've  made the  copy, right-click  on it  and
  968.                  select ``Open''  and  then  ``Settings''.    On  the
  969.                  ``Session'' page, select ``OS/2 full screen''.  Then
  970.                  go to the ``General'' page and type a new title:
  971.  
  972.                       Title:              Hamilton C shell
  973.                                           Full Screen
  974.  
  975.  
  976.  
  977.  
  978.                                       Page 9
  979.  
  980.      Installation
  981.  
  982.  
  983.                  Close the  Settings window  for the copy by pressing
  984.                  Alt-F4.
  985.  
  986.             9.   All  the   material  in  the  samples  directory  is
  987.                  provided for  its tutorial value; you may or may not
  988.                  wish to copy it onto your hard disk.
  989.  
  990.             10.  Reboot your  system before starting Hamilton C shell
  991.                  for the  first time.  This causes the new statements
  992.                  in config.sys to take effect.
  993.  
  994.  
  995.  
  996.  
  997.  
  998.  
  999.  
  1000.  
  1001.  
  1002.  
  1003.  
  1004.  
  1005.  
  1006.  
  1007.  
  1008.  
  1009.  
  1010.  
  1011.  
  1012.  
  1013.  
  1014.  
  1015.  
  1016.  
  1017.  
  1018.  
  1019.  
  1020.  
  1021.  
  1022.  
  1023.  
  1024.  
  1025.  
  1026.  
  1027.  
  1028.  
  1029.  
  1030.  
  1031.  
  1032.  
  1033.  
  1034.  
  1035.  
  1036.  
  1037.  
  1038.  
  1039.  
  1040.                                      Page 10
  1041.  
  1042.                                                                  Installation
  1043.  
  1044.  
  1045.             Installation as the Default Command Processor
  1046.  
  1047.             The C  shell can also be installed as the default command
  1048.             processor OS/2  protected mode,  meaning you  specify it,
  1049.             not cmd.exe  in your config.sys.  The principal advantage
  1050.             is that  when the  when the C shell is run as the default
  1051.             command processor,  PM allows  the C  shell to change its
  1052.             own title  bar and,  under OS/2  1.3 or  2.x (but not the
  1053.             6.167 Beta  or LA builds), its own icon to show what it's
  1054.             running.   This can  be quite helpful if you have lots of
  1055.             copies of  the shell  running minimized and would like to
  1056.             know what each one is doing.
  1057.  
  1058.             The disadvantage  is that  the installation  is  slightly
  1059.             messy and it does disable cmd.exe's ability to change its
  1060.             title bar  and icon.   For these reasons, most users will
  1061.             want to  wait until  they've gained some familiarity with
  1062.             the C shell and with OS/2 before installing it this way.
  1063.  
  1064.             To install  the C shell as the default command processor,
  1065.             follow the  instructions for  the basic  installation but
  1066.             then make these changes, as appropriate for your system:
  1067.  
  1068.  
  1069.  
  1070.             Default Command Processor Installation Procedure  (OS/2
  1071.             1.2 or 1.3)
  1072.  
  1073.             1.   Edit  the   PROTSHELL  line   in  your   config.sys,
  1074.                  replacing  the   pathname  and  any  parameters  for
  1075.                  cmd.exe  (remembering   what  they  were)  with  the
  1076.                  pathname for the C shell and a -L (login) parameter.
  1077.                  The resulting line should look something like this:
  1078.  
  1079.                           PROTSHELL=C:\OS2\PMSHELL.EXE C:\OS2\OS2.INI
  1080.                               C:\OS2\OS2SYS.INI C:\OS2\BIN\CSH.EXE -L
  1081.  
  1082.             2.   Change the  pathname you  specify for the C shell in
  1083.                  Start Programs  or Group-Main  to *  (an  asterisk).
  1084.                  Also, change  the parameters line to be either blank
  1085.                  (1.1 or 1.2) or (1.3):
  1086.  
  1087.                       /K "%*"
  1088.  
  1089.             3.   Change the  entries (probably  named ``OS/2 Window''
  1090.                  or ``OS/2  Full Screen'')  in  Group-Main  or  Start
  1091.                  Programs  for   cmd.exe  to  fill  in  the  complete
  1092.                  pathname for  cmd.exe instead  of an  asterisk.  Set
  1093.                  the  parameters   to  whatever   you  had  specified
  1094.                  following the  pathname for cmd.exe (if anything) in
  1095.                  your config.sys before changing it in step 1.
  1096.  
  1097.             4.   Change any  entries in  any of  your program  groups
  1098.                  which invoke  .cmd scripts  to run  them via cmd.exe
  1099.  
  1100.  
  1101.  
  1102.                                      Page 11
  1103.  
  1104.      Installation
  1105.  
  1106.  
  1107.                  explicitly.   For example,  if you had an entry that
  1108.                  specified the  program ``c:\myapp\foo.cmd'',  change
  1109.                  that to:
  1110.  
  1111.                       Path and file name:  c:\os2\cmd.exe
  1112.                       Parameters: /C c:\myapp\foo.cmd ...any
  1113.                       additional parameters...
  1114.  
  1115.             5.   Reboot.
  1116.  
  1117.  
  1118.  
  1119.  
  1120.  
  1121.  
  1122.  
  1123.  
  1124.  
  1125.  
  1126.  
  1127.  
  1128.  
  1129.  
  1130.  
  1131.  
  1132.  
  1133.  
  1134.  
  1135.  
  1136.  
  1137.  
  1138.  
  1139.  
  1140.  
  1141.  
  1142.  
  1143.  
  1144.  
  1145.  
  1146.  
  1147.  
  1148.  
  1149.  
  1150.  
  1151.  
  1152.  
  1153.  
  1154.  
  1155.  
  1156.  
  1157.  
  1158.  
  1159.  
  1160.  
  1161.  
  1162.  
  1163.  
  1164.                                      Page 12
  1165.  
  1166.                                                                  Installation
  1167.  
  1168.  
  1169.             Default Command Processor Installation Procedure  (OS/2
  1170.             2.x)
  1171.  
  1172.             1.   Edit your  config.sys to  set OS2_SHELL  to point to
  1173.                  the C shell, specifying the -L (login) option, e.g.,
  1174.  
  1175.                       set  OS2_SHELL=c:\hamilton\bin\csh.exe -L
  1176.  
  1177.             2.   Modify the  Settings for  the OS/2  Window and  OS/2
  1178.                  Full Screen  icons to show the full path for cmd.exe
  1179.                  (e.g., ``c:\os2\cmd.exe'')  rather than  an asterisk
  1180.                  on the Program page.
  1181.  
  1182.             3.   Modify the  Settings for  the Hamilton C shell icons
  1183.                  to specify an asterisk pathname (meaning the default
  1184.                  shell),  deleting   any  mention   of  any   startup
  1185.                  parameters and  explicitly specifying  the  C  shell
  1186.                  icon rather than the default icon:
  1187.  
  1188.                  a.   Right-click on the icon and open the Settings.
  1189.  
  1190.                  b.   On the Program page, set
  1191.  
  1192.                       Path and file name: *
  1193.                       Parameters:
  1194.  
  1195.                  c.   Select ``Find...'' next to the icon display.
  1196.  
  1197.                  d.   Select ``Locate'' on the Find screen.
  1198.  
  1199.                  e.   Select the  ``Path'' page  on the Locate Folder
  1200.                       screen.
  1201.  
  1202.                  f.   Type the  pathname of  the directory containing
  1203.                       the  C  shell's  csh.ico  icon  file.    (E.g.,
  1204.                       ``c:\hamilton\bin''.)
  1205.  
  1206.                  g.   Press the  ``OK'' button  on the  Locate Folder
  1207.                       screen.
  1208.  
  1209.                  h.   Type ``csh.ico''  in the Name field on the Find
  1210.                       screen.
  1211.  
  1212.                  i.   Press the ``Find'' button.
  1213.  
  1214.                  j.   The Find  Results screen should appear with the
  1215.                       C shell  icon highlighted.   Press  the  ``OK''
  1216.                       button.
  1217.  
  1218.                  k.   Back in the General Settings screen, you should
  1219.                       now see  the C  shell's icon.   Press Alt-F4 to
  1220.                       close the screen.
  1221.  
  1222.  
  1223.  
  1224.  
  1225.  
  1226.                                      Page 13
  1227.  
  1228.      Installation
  1229.  
  1230.  
  1231.             4.   When you  reboot, the  C shell  will be  the default
  1232.                  shell and  it will appear with its correct icon both
  1233.                  for starting and when you minimize it.
  1234.  
  1235.  
  1236.  
  1237.  
  1238.  
  1239.  
  1240.  
  1241.  
  1242.  
  1243.  
  1244.  
  1245.  
  1246.  
  1247.  
  1248.  
  1249.  
  1250.  
  1251.  
  1252.  
  1253.  
  1254.  
  1255.  
  1256.  
  1257.  
  1258.  
  1259.  
  1260.  
  1261.  
  1262.  
  1263.  
  1264.  
  1265.  
  1266.  
  1267.  
  1268.  
  1269.  
  1270.  
  1271.  
  1272.  
  1273.  
  1274.  
  1275.  
  1276.  
  1277.  
  1278.  
  1279.  
  1280.  
  1281.  
  1282.  
  1283.  
  1284.  
  1285.  
  1286.  
  1287.  
  1288.                                      Page 14
  1289.  
  1290.                                                                  Installation
  1291.  
  1292.  
  1293.             
  1294.  
  1295.  
  1296.  
  1297.  
  1298.  
  1299.  
  1300.  
  1301.  
  1302.  
  1303.  
  1304.  
  1305.  
  1306.  
  1307.  
  1308.  
  1309.  
  1310.  
  1311.  
  1312.  
  1313.  
  1314.  
  1315.  
  1316.  
  1317.  
  1318.  
  1319.  
  1320.  
  1321.  
  1322.  
  1323.  
  1324.  
  1325.  
  1326.  
  1327.  
  1328.  
  1329.  
  1330.  
  1331.  
  1332.  
  1333.  
  1334.  
  1335.  
  1336.  
  1337.  
  1338.  
  1339.  
  1340.  
  1341.  
  1342.  
  1343.  
  1344.  
  1345.  
  1346.  
  1347.  
  1348.  
  1349.  
  1350.                                      Page 15
  1351.  
  1352.      Installation
  1353.  
  1354.  
  1355.             
  1356.  
  1357.  
  1358.                            Installation on Windows NT
  1359.  
  1360.  
  1361.             This section  describes how  to install  the  Windows  NT
  1362.             version of Hamilton C shell.
  1363.  
  1364.  
  1365.  
  1366.             System Requirements:
  1367.  
  1368.             Installation  requires  a  386-,  486-  or  Pentium-based
  1369.             machine for  the Intel  x86 version,  a  MIPS  R4000-  or
  1370.             R4400-based machine  for the  MIPS version or a DEC Alpha
  1371.             AXP-based machine  for the  Alpha version  of Hamilton  C
  1372.             shell.   The machine must be running the final release of
  1373.             Windows NT,  build 511  (on Intel or MIPS) or 528 (Alpha)
  1374.             or later.   Roughly  2.2 MB  of disk  space is used on an
  1375.             Intel machine, 3.7MB on a MIPS or 4.5MB on an Alpha.
  1376.  
  1377.  
  1378.  
  1379.             Basic Installation:
  1380.  
  1381.             1.   Copy the contents of the bin and samples directories
  1382.                  onto your hard disk, putting them anywhere you like.
  1383.                  (Notice that  the bin directory is too big to fit on
  1384.                  one diskette;  you'll have  to merge the two or more
  1385.                  diskettes, depending on which system you have.)
  1386.  
  1387.             2.   Copy the  login.csh and  startup.csh files  into any
  1388.                  directory you  care to  designate as  your  ``home''
  1389.                  directory.   The significance of a home directory is
  1390.                  principally that  it will  be convenient  to specify
  1391.                  pathnames relative to this directory.
  1392.  
  1393.             3.   Edit   the    login.csh   and   startup.csh   files,
  1394.                  customizing them  to meet your needs.  The login.csh
  1395.                  file has  a lot of comments in it which can take the
  1396.                  shell a  second or  more to read each time it starts
  1397.                  up; you'll  almost certainly  want to delete some of
  1398.                  these comments  once you've  read them  so the shell
  1399.                  will start up faster.
  1400.  
  1401.             4.   Edit  the   environment  variables  by  opening  the
  1402.                  Control Panel  and then,  within that,  opening  the
  1403.                  system icon.
  1404.  
  1405.                  To define a variable through the Control Panel, type
  1406.                  the variable  name in the ``Variable:'' fill-in box,
  1407.                  the value  in the  ``Value:'' box  and click  on the
  1408.                  ``Set'' button.
  1409.  
  1410.  
  1411.  
  1412.                                      Page 16
  1413.  
  1414.                                                                  Installation
  1415.  
  1416.  
  1417.                  a.   Create  or   edit  your   entry  for  the  PATH
  1418.                       variable, adding  the full  pathnames for the C
  1419.                       shell's bin  and  samples  directories  to  the
  1420.                       list.
  1421.  
  1422.                  b.   Create  an   entry  for  the  HOME  environment
  1423.                       variable,  setting   its  value   as  the  full
  1424.                       pathname of  the  directory  where  you  placed
  1425.                       login.csh and startup.csh.
  1426.  
  1427.                  c.   You may  also want  to include  definitions for
  1428.                       TABS  and  COLORS.    The  shell  and  all  the
  1429.                       utilities look for TABS to see if you want them
  1430.                       to display  text  with  tabs  expanded  out  to
  1431.                       something other  than the  default of  every  8
  1432.                       characters.
  1433.  
  1434.                       By  default,   the  C   shell  displays   white
  1435.                       characters on  a black  background.  The COLORS
  1436.                       variable lets  you choose  a  combination  from
  1437.                       this set:  black,  red,  green,  yellow,  blue,
  1438.                       magenta (or blue red), cyan (or blue green) and
  1439.                       white.   Foreground collows may also be bright,
  1440.                       dim, blink  or reverse.    The  keyword  ``on''
  1441.                       introduces  background  colors.    (Blink  only
  1442.                       causes true  blinking full-screen;  in  a  text
  1443.                       window, it  just makes the background brighter.
  1444.                       Also, yellow  is a  true yellow  only  if  it's
  1445.                       bright.    These  are  system  limitations  not
  1446.                       related to the C shell.)
  1447.  
  1448.                       Other color  settings you might want to specify
  1449.                       now or  at some  later time through the Control
  1450.                       Panel are  MOREPROMPT, MOREFILLIN and MOREERROR
  1451.                       (for customizing  the  more  utility's  command
  1452.                       line)  and   DELETIONS   and   ADDITIONS   (for
  1453.                       customizing the diff utility).
  1454.  
  1455.                       For more  information on setting screen colors,
  1456.                       please refer  to the the colors.csh file in the
  1457.                       samples  directory   or  to  the  Customization
  1458.                       chapter.
  1459.  
  1460.                  Here's an example of the settings you might specify:
  1461.  
  1462.                       HOME=d:\doug
  1463.                       PATH=d:\hamilton\bin;d:\hamilton;samples
  1464.                       COLORS=white on blue
  1465.                       TABS=3
  1466.                       ADDITIONS=bright white on green
  1467.                       DELETIONS=bright white on red
  1468.                       MOREPROMPT=red on white
  1469.                       MOREFILLIN=black
  1470.                       MOREERROR=bright white on red
  1471.  
  1472.  
  1473.  
  1474.                                      Page 17
  1475.  
  1476.      Installation
  1477.  
  1478.  
  1479.             5.   Add csh.exe  with the  title ``Hamilton C shell'' to
  1480.                  the Program Manager.  To do this, pull-down ``File''
  1481.                  and select  ``New''.    A  pop-up will appear asking
  1482.                  that you  confirm this  will be  a new Program Item.
  1483.                  On the next pop-up, fill in:
  1484.  
  1485.                       Description:        Hamilton C shell
  1486.                       Command Line:       ....as
  1487.                       appropriate....\csh.exe -L
  1488.  
  1489.                  The ``-L'' part tells csh.exe when it starts up that
  1490.                  it's a  ``login'' shell,  which means it should look
  1491.                  for a login.csh file.
  1492.  
  1493.  
  1494.  
  1495.  
  1496.  
  1497.  
  1498.  
  1499.  
  1500.  
  1501.  
  1502.  
  1503.  
  1504.  
  1505.  
  1506.  
  1507.  
  1508.  
  1509.  
  1510.  
  1511.  
  1512.  
  1513.  
  1514.  
  1515.  
  1516.  
  1517.  
  1518.  
  1519.  
  1520.  
  1521.  
  1522.  
  1523.  
  1524.  
  1525.  
  1526.  
  1527.  
  1528.  
  1529.  
  1530.  
  1531.  
  1532.  
  1533.  
  1534.  
  1535.  
  1536.                                      Page 18
  1537.  
  1538.                                                               Common Problems
  1539.  
  1540.  
  1541.             
  1542.  
  1543.  
  1544.                                  Common Problems
  1545.  
  1546.  
  1547.  
  1548.  
  1549.             When I try to start the C shell in a new window, it dies
  1550.             and goes away before I can read its messages.
  1551.  
  1552.             You've probably  made an error on the ``Parameters'' line
  1553.             under OS/2  or in  the ``Command  Line'' under NT.  Under
  1554.             NT, select  the icon  for Hamilton C shell and press Alt-
  1555.             Enter to examine the properties.
  1556.  
  1557.             Under OS/2,  you can  force the  window will  to stay  up
  1558.             after the  shell exits  so you  can read  the message  by
  1559.             following the instructions appropriate for your system:
  1560.  
  1561.             OS/2 1.1:  Go to the ``How to Run the Program'' screen by
  1562.                  clicking on  the C shell entry in ``Start Programs''
  1563.                  and  pulling   down   ``Program''   then   selecting
  1564.                  ``Change...''.    Click  on  the  check  box  beside
  1565.                  ``Close the window...'' and press Enter.
  1566.  
  1567.             OS/2 1.2 or 1.3:  Click on the C shell entry in ``Group -
  1568.                  Main'',  pulling   down  ``Program''  and  selecting
  1569.                  ``Properties''.   Push the ``Options...'' button and
  1570.                  click on  the check  box next  to ``Close  window on
  1571.                  exit'', removing the X.
  1572.  
  1573.             OS/2 2.x:   Right-click  on the  icon and select ``Open''
  1574.                  followed by  ``Settings.''   On  the  Session  page,
  1575.                  click on  the check  box next  to ``Close  window on
  1576.                  exit'', removing the check.
  1577.  
  1578.  
  1579.  
  1580.             The shell doesn't know how to run an external command.
  1581.  
  1582.                One of the environmental variables, particularly HOME,
  1583.             PATH or  COMSPEC is  probably set  incorrectly.   Typical
  1584.             symptoms are  that the  shell doesn't seem to know how to
  1585.             find an  external command  or that it doesn't know how to
  1586.             run a .cmd file, etc.  Another variation might be that it
  1587.             runs the  old IBM  more.com rather than the new more.exe.
  1588.             If you  experience symptoms  like these, first check that
  1589.             these variables are set sensibly.
  1590.  
  1591.                The other  common possibility  under OS/2  1.x is that
  1592.             you're using  a network  and have  execute, but  not read
  1593.             access to the application you're trying to run.  Due to a
  1594.             bug in  the OS/2  1.x kernel,  the C shell cannot use the
  1595.  
  1596.  
  1597.  
  1598.                                      Page 19
  1599.  
  1600.      Common Problems
  1601.  
  1602.  
  1603.             kernel's DosQAppType  function to  determine whether  the
  1604.             application should  be started  full-screen,  in  a  text
  1605.             window or  as a  PM graphics application.  Instead, the C
  1606.             shell is  forced to  read the  application's .exe  header
  1607.             itself; if  it can't  read it,  it can't  run  it.    The
  1608.             solution is to be sure you have read access.
  1609.  
  1610.  
  1611.  
  1612.  
  1613.  
  1614.  
  1615.  
  1616.  
  1617.  
  1618.  
  1619.  
  1620.  
  1621.  
  1622.  
  1623.  
  1624.  
  1625.  
  1626.  
  1627.  
  1628.  
  1629.  
  1630.  
  1631.  
  1632.  
  1633.  
  1634.  
  1635.  
  1636.  
  1637.  
  1638.  
  1639.  
  1640.  
  1641.  
  1642.  
  1643.  
  1644.  
  1645.  
  1646.  
  1647.  
  1648.  
  1649.  
  1650.  
  1651.  
  1652.  
  1653.  
  1654.  
  1655.  
  1656.  
  1657.  
  1658.  
  1659.  
  1660.                                      Page 20
  1661.  
  1662.                                                               Common Problems
  1663.  
  1664.  
  1665.             The shell won't run my new program.
  1666.  
  1667.                Path hashing  can sometimes produce surprising results
  1668.             if you  create a  newer version in your current directory
  1669.             of a  command that already exists in another of your path
  1670.             directories.   The shell won't know you've done this; its
  1671.             hash will still only list the older version.  To overcome
  1672.             this problem, use either the rehash or unhash commands.
  1673.  
  1674.  
  1675.  
  1676.             The shell won't execute commands in the current
  1677.             directory.
  1678.  
  1679.                Your should  add the  current directory to the list of
  1680.             directories in  the PATH variable.  cmd.exe always checks
  1681.             the current  directory before  looking in any of the PATH
  1682.             directories.    Hamilton  C  shell  does  not  make  this
  1683.             assumption; if you want the current directory to be first
  1684.             one checked, you should specify it explicitly as ``.'' at
  1685.             the beginning of the list.  For example:
  1686.  
  1687.                  setenv PATH = '.;c:\os2;c:\os2\bin'
  1688.  
  1689.  
  1690.  
  1691.             The shell keeps running the old version my shell
  1692.             procedure.
  1693.  
  1694.                If you  define a  shell procedure  with proc in a .csh
  1695.             script file and then execute the script, the procedure is
  1696.             compiled into  an internal form that's much faster to run
  1697.             and it's  kept around  in memory  to make it run the next
  1698.             time even  faster.   If you change the text in the script
  1699.             file but  don't explicitly  throw away the old definition
  1700.             using unproc,  the C  shell won't  know it's  supposed to
  1701.             recompile.
  1702.  
  1703.  
  1704.  
  1705.             The shell won't run any cmd.exe internal commands.
  1706.  
  1707.                Most probably,  the  shell  is  unable  to  find  your
  1708.             startup.csh file  when it  starts up.   This  is the file
  1709.             that should  hold the aliases the shell uses to intercept
  1710.             cmd.exe's built-in commands.  Check to see that your HOME
  1711.             variable is  set to  the directory  where  you've  placed
  1712.             startup.csh and that your startup.csh file isn't garbled.
  1713.  
  1714.  
  1715.  
  1716.             When I start an application from the C shell, it dies
  1717.             immediately.
  1718.  
  1719.  
  1720.  
  1721.  
  1722.                                      Page 21
  1723.  
  1724.      Common Problems
  1725.  
  1726.  
  1727.                Under OS/2,  if you  find  that  an  application  dies
  1728.             immediately after  starting, check  that the .exe file is
  1729.             properly marked with its type, i.e., full-screen, PM text
  1730.             windowable or  PM graphics.   The shell tries to start up
  1731.             an application in accordance with the way it's marked; if
  1732.             it's marked  wrong, the application just won't run.  Even
  1733.             very recently, a number of PM applications including even
  1734.             e.exe, the  System Editor,  were being  shipped unmarked,
  1735.             which by  convention is supposed to mean full-screen.  To
  1736.             look at  or change  how an application is marked, use the
  1737.             markexe.exe utility.  (Type ``markexe -h'' for help.)
  1738.  
  1739.                Another possibility  is that the application has a bug
  1740.             that makes  it fail  if the  maximum file handle count it
  1741.             inherits from  its parent  process is  greater  than  20.
  1742.             This problem  has been  seen in some past releases of the
  1743.             Microsoft linker  (discussed below)  and of  WordPerfect,
  1744.             for example.   You  can force the C shell not to bump the
  1745.             file limit when it starts up using the -Z option but this
  1746.             option only  works from the Start Programs (1.1) or Group
  1747.             (1.2) menus,  not from  the command  line.    (A  process
  1748.             always inherits  its initial  maximum file  handle  count
  1749.             from its parent; from there, a process can only raise its
  1750.             own limit, never lower it.)
  1751.  
  1752.  
  1753.  
  1754.             The Microsoft OS/2 linker fails under the C shell even
  1755.             though it works fine under cmd.exe.
  1756.  
  1757.                Microsoft has  determined  there  was  a  bug  in  the
  1758.             version of  the C  library used  to  build  the  link.exe
  1759.             distributed with  MS C  5.1.  The linker can fail if it's
  1760.             run as  a child  of a  process that  has a  maximum  file
  1761.             handle count  greater than  20; this is a problem because
  1762.             the  C  shell  sets  its  maximum  to  255.    If  you're
  1763.             encountering this  problem, try  patching  your  link.exe
  1764.             file with  the patchlnk.exe  utility.  (Type ``patchlnk -
  1765.             h'' for help.)
  1766.  
  1767.  
  1768.  
  1769.             When I try to run Microsoft's make.exe in the background
  1770.             it hangs.
  1771.  
  1772.                This is  a known  problem under  OS/2  with  make  and
  1773.             certain other  applications  that  need  to  spawn  child
  1774.             processes of  their own.  The OS/2 process initialization
  1775.             and completion logic requests a semaphore in KBDCALLS.DLL
  1776.             that's already  owned by  whatever process in that window
  1777.             is already  sleeping in  a KbdCharIn call.  Until another
  1778.             keystroke is  pressed, that  semaphore is  never released
  1779.             and the background processes are never allowed to cleanly
  1780.             exit.   This problem  has been  fixed  in  OS/2  2.x  and
  1781.  
  1782.  
  1783.  
  1784.                                      Page 22
  1785.  
  1786.                                                               Common Problems
  1787.  
  1788.  
  1789.             through CSD  5050 for  OS/2 1.3  with a new KBDCALLS.DLL.
  1790.             That DLL  for 1.3  is available  on request from Hamilton
  1791.             Laboratories and can be downloaded from the listings area
  1792.             in the ``hamilton'' conference on BIX.
  1793.  
  1794.  
  1795.  
  1796.             copy or rename *.* doesn't work right.
  1797.  
  1798.                copy, xcopy,  rename and  del like  to  do  their  own
  1799.             wildcard expansion.   To make them work sensibly, be sure
  1800.             your startup.csh  file includes  and  that  you  use  the
  1801.             aliases and  procedure definitions we supply to intercept
  1802.             these commands  to turn  off shell  wildcarding just long
  1803.             enough to  run them.  These definitions can also serve as
  1804.             a model  if you  discover other applications that must do
  1805.             their own  wildcarding.   For more  information, refer to
  1806.             the discussion on page 24.
  1807.  
  1808.  
  1809.  
  1810.             The -! option doesn't work.
  1811.  
  1812.                The exclamation  point is  a special character for the
  1813.             shell.   The shell  lets you pick up text out of previous
  1814.             commands using  history references  that begin with ``!''
  1815.             followed  by   a  string  that  tells  what  text  you're
  1816.             retrieving.  To avoid having an exclamation confused as a
  1817.             history reference,  be sure the exclamation is at the end
  1818.             of a word, so the next character is a space or a tab.
  1819.  
  1820.  
  1821.  
  1822.             grep '^foo' doesn't work.
  1823.  
  1824.                The circumflex  has  special  meaning  as  the  escape
  1825.             character to  the C  shell, even  inside quotes.   If you
  1826.             want to  pass a  literal ``^'' to grep (or anything else)
  1827.             from the  command line,  you must  type ``^^'' unless the
  1828.             immediately preceding character was ``[''.
  1829.  
  1830.  
  1831.  
  1832.             When I list a directory over the network, not everything
  1833.             shows up.
  1834.  
  1835.                This is  a known  bug in the OS/2 networking code, not
  1836.             the C  shell.  The problem occurs if (1) the directory is
  1837.             read over a network, (2) directory entries are being read
  1838.             in blocks  (for higher performance) rather than one-at-a-
  1839.             time and  (3) the  total number  of characters in all the
  1840.             filenames in that directory happens to be just right.  In
  1841.             all cases  observed, adding  or  deleting  any  arbitrary
  1842.             entry in  the directory  makes the  problem go away.  The
  1843.  
  1844.  
  1845.  
  1846.                                      Page 23
  1847.  
  1848.      Common Problems
  1849.  
  1850.  
  1851.             bug affects  the C  shell and  its utilities because they
  1852.             use blocked  reads; simpler  programs like  cmd.exe's DIR
  1853.             are unaffected because they read one entry at a time.
  1854.  
  1855.                The bug appears to have been introduced in IBM OS/2 EE
  1856.             CSD WR04098  and Microsoft  Lan Manager  2.0, both issued
  1857.             around year-end,  1990.  IBM has verified the problem and
  1858.             has developed  a fix,  which is  now shipping  as part of
  1859.             OS/2 EE  1.3.  If you encounter the problem and you're an
  1860.             IBM customer,  you should  call 1-800-237-5511 or contact
  1861.             your local  IBM representative  and ask for a copy of the
  1862.             new netwksta.sys  file being distributed as APAR IC02287.
  1863.             You can also download this file from the listings area of
  1864.             the ``hamilton''  vendor support  conference  on  Bix  or
  1865.             contact us directly and we'll mail you a copy.
  1866.  
  1867.                In the  meantime, this  release contains a work-around
  1868.             for disabling  the block  read feature.  If you create an
  1869.             environmental variable,  NETWORKBUG, and  set it equal to
  1870.             1, directory  reads  will  be  done  only  one-at-a-time,
  1871.             ensuring correct  results at  all times, albeit with some
  1872.             degradation in  performance.  You can do this either from
  1873.             the C shell:
  1874.  
  1875.                  setenv NETWORKBUG = 1
  1876.  
  1877.             or in your config.sys:
  1878.  
  1879.                  SET NETWORKBUG=1
  1880.  
  1881.  
  1882.  
  1883.             du, pwd and vol waste time sitting and spinning when they
  1884.             hit a removable drive that's empty.
  1885.  
  1886.                If you  have a removable media device other than A: or
  1887.             B:, these  utilities will  normally try  to report  them.
  1888.             That's probably  not you  want, at least not usually; you
  1889.             can specify  just the  set of drives you do want reported
  1890.             using the DRIVEMASK environmental variable.
  1891.  
  1892.  
  1893.  
  1894.  
  1895.  
  1896.  
  1897.  
  1898.  
  1899.  
  1900.  
  1901.  
  1902.  
  1903.  
  1904.  
  1905.  
  1906.  
  1907.  
  1908.                                      Page 24
  1909.  
  1910.                                                               Common Problems
  1911.  
  1912.  
  1913.             cd /foo doesn't work.
  1914.  
  1915.                Hamilton C shell tries to serve users coming both UNIX
  1916.             and MS-DOS  backgrounds.  To do this, the C shell and all
  1917.             the utilities  accept command  line options starting with
  1918.             either ``-''  (UNIX-style) or  ``/'' (DOS-style).    They
  1919.             also recognize  filenames typed  with either  forward  or
  1920.             backward slashes.   But  when you type ``cd /foo'', the C
  1921.             shell guesses wrong and thinks you're trying to give it a
  1922.             command line option that it can't recognize.
  1923.  
  1924.                If this  is  really  not  what  you  intend,  set  the
  1925.             SWITCHCHARS environmental  variable to  just the specific
  1926.             characters you  want recognized.  E.g., you might include
  1927.             this in your config.sys to have only ``-'' recognized:
  1928.  
  1929.                  set SWITCHCHARS=-
  1930.  
  1931.  
  1932.  
  1933.             I've just installed OS/2 1.2 and suddenly my environment
  1934.             variables don't work.
  1935.  
  1936.                The auto  install program  distributed with  the fall,
  1937.             1989 releases  of OS/2  1.2 from  Microsoft and IBM has a
  1938.             bug.   It tries  to automatically  convert entries on the
  1939.             1.1 Start Programs menu into corresponding entries on the
  1940.             new 1.2  Group Main  menu.   If the  parameters line  for
  1941.             starting a  program has  text on  it (as  the  C  shell's
  1942.             does), the  entry is garbled even though it looks correct
  1943.             and causes  a garbled  environment to  be passed  to  the
  1944.             shell.   Editing the entry does not fix the problem.  The
  1945.             only solution  is to  delete the  entry and rekey it from
  1946.             scratch.
  1947.  
  1948.  
  1949.  
  1950.             I can't set my own screen colors.
  1951.  
  1952.                Yes, you  can (finally,  in this latest release.)  But
  1953.             you cannot  do it just by embedding ANSI escape sequences
  1954.             into your prompt since the C shell will immediately reset
  1955.             the colors back to what it thinks they should be.  To set
  1956.             your own  preferences for screen colors, you must use the
  1957.             COLORS  environmental  variable.    See  the  chapter  on
  1958.             customizing the  shell or  the colors.csh  script in  the
  1959.             samples directory for more information.
  1960.  
  1961.  
  1962.  
  1963.             The C shell's icon won't display in Group-Main.
  1964.  
  1965.                If you  install the  C shell  as the  default  command
  1966.             processor by  specifying it  on  the  PROTSHELL  line  in
  1967.  
  1968.  
  1969.  
  1970.                                      Page 25
  1971.  
  1972.      Common Problems
  1973.  
  1974.  
  1975.             config.sys and  entering its path as ``*'' in Group-Main,
  1976.             you will  see only the default OS/2 icon in Group-Main if
  1977.             you select  View Icon.  If you start, then minimize the C
  1978.             shell, it  will have the correct icon, however.  This has
  1979.             been reported to IBM.  Their response is that, by design,
  1980.             when the  path is  an ``*,''  the  Group  code  does  not
  1981.             attempt to  resolve  the  actual  pathname  (and  whether
  1982.             there's any  icon associated  with it) until you actually
  1983.             click on  the entry  to start  it.  They agree this means
  1984.             you will  not see  the correct icon in the Group menu but
  1985.             claim this is what they intended and that it's not a bug.
  1986.  
  1987.  
  1988.  
  1989.             more crashes on the OS/2 2.0 Beta and LA Releases.
  1990.  
  1991.                The dynamic  link library  supporting 8514 displays in
  1992.             the beta  and LA releases from IBM has a bug which causes
  1993.             some VIO  applications, including  more, to  crash with a
  1994.             protection violation  if they're  run in  a text  window.
  1995.             They work  fine full-screen.  This problem has been fixed
  1996.             in the GA build.
  1997.  
  1998.  
  1999.  
  2000.             more hangs or exits prematurely on the OS/2 2.0 6.167 and
  2001.             LA releases.
  2002.  
  2003.                Under the  6.167 and  LA releases,  the  8514  display
  2004.             driver is  completely unusable.   It  even  has  problems
  2005.             repainting the  screen after  a menu  has been  closed or
  2006.             displaying icons in the templates folder.  It even causes
  2007.             more to hang the whole system if you have an 8514.
  2008.  
  2009.                But even using the VGA driver, random problems will be
  2010.             observed due, apparently, to bugs in the keyboard driver.
  2011.             Depending on  what's fed  to it through a pipe, more will
  2012.             occasionally prematurely  exit after the first screenful.
  2013.             All these problems have been fixed in the GA release.
  2014.  
  2015.  
  2016.  
  2017.             The C shell can't change its title bar or icon under the
  2018.             OS/2 2.0 6.167 Beta and LA releases.
  2019.  
  2020.                This functionality  was disabled in the 6.167 Beta and
  2021.             LA releases  as part  of the  work to  add the  Workplace
  2022.             Shell.  This problem has been fixed in the GA release.
  2023.  
  2024.  
  2025.  
  2026.             Alt-Enter doesn't work to grab commands from the history
  2027.             list under Windows NT and the OS/2 2.0 6.167 Beta
  2028.             Release.
  2029.  
  2030.  
  2031.  
  2032.                                      Page 26
  2033.  
  2034.                                                               Common Problems
  2035.  
  2036.  
  2037.                Under Windows  NT and  OS/2 2.0  6.167,  Alt-Enter  is
  2038.             gobbled up  by the system as a keystroke combination used
  2039.             to signal  that an application should be toggled back and
  2040.             forth between  the desktop  and  a  full-screen  session.
  2041.             Under the  these systens, you'll have to type Ctrl-Shift-
  2042.             Enter instead.
  2043.  
  2044.  
  2045.  
  2046.             The C shell (and lots of other applications) only have
  2047.             default icons under the OS/2 2.0 6.167 Beta and LA
  2048.             Releases.
  2049.  
  2050.                The Workplace  Shell does not support .ico files.  All
  2051.             icons  for  text  applications  must  be  stored  in  the
  2052.             extended attributes.   The  latest builds  of the C shell
  2053.             have the  icon both  in the EA and in an .ico file but if
  2054.             you copied  the C  shell onto  your disk  with a  utility
  2055.             (e.g.., something  other than  cp) that  does not support
  2056.             EA's, that information probably got lost.
  2057.  
  2058.                To put  an icon  into the extended attributes, use the
  2059.             OS/2 1.3  File Manager,  selecting the file, pulling down
  2060.             ``Properties'' and selecting ``Icon...''.
  2061.  
  2062.  
  2063.  
  2064.             I just installed the C shell as the PROTSHELL and now
  2065.             when I start Commmunications Manager, it dies
  2066.             immediately.
  2067.  
  2068.                Communications Manager  is invoked  via a  .cmd script
  2069.             file.   Follow the  instructions in  step 4 on page 11 to
  2070.             rewrite that  entry to  start that  script explicitly via
  2071.             cmd.exe.
  2072.  
  2073.  
  2074.  
  2075.             I can't  wildcard filenames with $, quoted or escaped
  2076.             characters in them.
  2077.  
  2078.                Yes, you can (finally, in this latest release.)  To do
  2079.             so, just  quote or  escape the special characters.  E.g.,
  2080.             to get  all the  files that  begin with $, you might type
  2081.             ^$* or '$'* .
  2082.  
  2083.  
  2084.  
  2085.             I can't run the C shell inside an Epsilon editor window.
  2086.  
  2087.                The Epsilon  editor  tries  to  run  whatever  command
  2088.             processor you  use by  creating a full-screen session and
  2089.             doing a  KbdRegister to  intercept  the  KbdStringIn  API
  2090.             entry so  that Epsilon  can feed  it whatever you type in
  2091.  
  2092.  
  2093.  
  2094.                                      Page 27
  2095.  
  2096.      Common Problems
  2097.  
  2098.  
  2099.             the editor  window.   Output (stdout and stderr) from the
  2100.             child session  is redirected  over a  pipe  back  to  the
  2101.             editor.
  2102.  
  2103.                There are  a couple  problems in  their approach:  (1)
  2104.             They neglected  to consider that not all applications use
  2105.             KbdStringIn; if  stdin is  attached to  a keyboard, the C
  2106.             shell reads  a keystroke  at a  time using  KbdCharIn and
  2107.             those calls still end up tied to that full-screen session
  2108.             rather than  being redirected.   (If stdin is attached to
  2109.             anything else,  it uses  DosRead calls.)   The authors of
  2110.             Epsilon really  should have  intercepted the whole set of
  2111.             Kbd  calls,   not  just   one  of  them.    (2)  Not  all
  2112.             applications write  their output  to  stdout  or  stderr;
  2113.             applications like  more, that  use Vio  output, won't run
  2114.             properly.   Their  output  appears  in  that  full-screen
  2115.             session, not  back in  the editor window.  Epsilon really
  2116.             should be  doing a  VioRegister to  grab the  Vio  output
  2117.             also.
  2118.  
  2119.                We are  working with  Lugaru Software  (the authors of
  2120.             Epsilon) on  a solution that should be available shortly.
  2121.             A partial workaround is to tell Epsilon to use a separate
  2122.             program, which  just reads  input and  pipes it  to the C
  2123.             shell.   Marty Klos  at IBM has written a small C program
  2124.             to do that and placed it in the public domain.  A copy is
  2125.             available on  request from  us or  may be downloaded from
  2126.             the listings  area of  the  ``hamilton''  vendor  support
  2127.             conference on BIX.
  2128.  
  2129.  
  2130.  
  2131.             rm doesn't remove anything, it just puts everything in a
  2132.             hidden directory.
  2133.  
  2134.                You're  using   the  notorious  Microsoft  rm  command
  2135.             instead of  the Hamilton  rm.   The Microsoft  rm doesn't
  2136.             remove anything;  it just  puts things in a hidden system
  2137.             directory.   Hamilton rm  is actually  in  hrm.exe  under
  2138.             Windows  NT   and  should   be  aliased  to  rm  in  your
  2139.             startup.csh file.   Fix  that and then, to get rid of all
  2140.             those ``deleted'' directories:
  2141.  
  2142.                  cd \; rm -x `ls -1ra +H | dim | grep 'deleted$'`
  2143.  
  2144.  
  2145.  
  2146.  
  2147.  
  2148.  
  2149.  
  2150.  
  2151.  
  2152.  
  2153.  
  2154.  
  2155.  
  2156.                                      Page 28
  2157.  
  2158.                                                               Common Problems
  2159.  
  2160.  
  2161.             
  2162.  
  2163.  
  2164.  
  2165.  
  2166.  
  2167.  
  2168.  
  2169.  
  2170.  
  2171.  
  2172.  
  2173.  
  2174.  
  2175.  
  2176.  
  2177.  
  2178.  
  2179.  
  2180.  
  2181.  
  2182.  
  2183.  
  2184.  
  2185.  
  2186.  
  2187.  
  2188.  
  2189.  
  2190.  
  2191.  
  2192.  
  2193.  
  2194.  
  2195.  
  2196.  
  2197.  
  2198.  
  2199.  
  2200.  
  2201.  
  2202.  
  2203.  
  2204.  
  2205.  
  2206.  
  2207.  
  2208.  
  2209.  
  2210.  
  2211.  
  2212.  
  2213.  
  2214.  
  2215.  
  2216.  
  2217.  
  2218.                                      Page 29
  2219.  
  2220.      Support
  2221.  
  2222.  
  2223.             
  2224.  
  2225.  
  2226.                                  Product Support
  2227.  
  2228.  
  2229.                If you  encounter  problems  or  would  like  to  make
  2230.             suggestions for  a future  revision, please contact us by
  2231.             any of  the following  or by  regular mail;  we promise a
  2232.             prompt response.
  2233.  
  2234.                               Phone:     508-358-5715
  2235.                               FAX:       508-358-1113
  2236.                               MCI Mail:  389-0321
  2237.                               Telex:     6503890321
  2238.                               BIX:       hamilton
  2239.                               CompuServe: 70034,2025
  2240.                               Internet:  3890321@mcimail.com
  2241.  
  2242.                Also, on Bix, we have a vendor support conference.  Do
  2243.             a ``join  hamilton'' once  you get on or follow the menus
  2244.             into the conference system.
  2245.  
  2246.  
  2247.  
  2248.             Bug Reports
  2249.  
  2250.                If you  encounter what you believe to be a bug, please
  2251.             try to experiment to see what specific command or command
  2252.             sequence seems  to be  failing before calling.  A problem
  2253.             that's easily  reproducible is  obviously easier  to fix.
  2254.             Built in  to Hamilton C shell are a number of consistency
  2255.             checks to  trap bugs  before they  cause  damage  and  to
  2256.             snapshot enough  information  to  help  us  diagnose  and
  2257.             repair the  problem.   If the shell is actually crashing,
  2258.             look to  see if  a new  entry has been added to the error
  2259.             log, crash.csh,  in your home directory; that information
  2260.             will be useful.
  2261.  
  2262.                When you  call, we'll  try  to  provide  an  immediate
  2263.             workaround if  there is  one.   If the problem is serious
  2264.             but  straight-forwardly  correctable,  we  can  generally
  2265.             offer an  interim  release  at  no  charge  to  fix  that
  2266.             specific problem.   At the very least, we try to schedule
  2267.             it for an upcoming general release.
  2268.  
  2269.  
  2270.  
  2271.             Future Enhancements
  2272.  
  2273.                Work   continues    on   additional    features    and
  2274.             enhancements.   As they  become available, we want you to
  2275.             have them.
  2276.  
  2277.  
  2278.  
  2279.  
  2280.                                      Page 30
  2281.  
  2282.                                                                       Support
  2283.  
  2284.  
  2285.                Please return  the registration  form by  mail or FAX.
  2286.             Without that, we often have no way of knowing who you are
  2287.             to send  updates to.   This  is particularly true if your
  2288.             copy was  purchased  through  your  company's  purchasing
  2289.             department   or through  a retail  distributor.  Also, we
  2290.             look forward to your feedback as we strive to improve the
  2291.             product.
  2292.  
  2293.  
  2294.  
  2295.  
  2296.  
  2297.  
  2298.  
  2299.  
  2300.  
  2301.  
  2302.  
  2303.  
  2304.  
  2305.  
  2306.  
  2307.  
  2308.  
  2309.  
  2310.  
  2311.  
  2312.  
  2313.  
  2314.  
  2315.  
  2316.  
  2317.  
  2318.  
  2319.  
  2320.  
  2321.  
  2322.  
  2323.  
  2324.  
  2325.  
  2326.  
  2327.  
  2328.  
  2329.  
  2330.  
  2331.  
  2332.  
  2333.  
  2334.  
  2335.  
  2336.  
  2337.  
  2338.  
  2339.  
  2340.  
  2341.  
  2342.                                      Page 31
  2343.  
  2344.      Support
  2345.  
  2346.  
  2347.                
  2348.  
  2349.  
  2350.  
  2351.  
  2352.  
  2353.  
  2354.  
  2355.  
  2356.  
  2357.  
  2358.  
  2359.  
  2360.  
  2361.  
  2362.  
  2363.  
  2364.  
  2365.  
  2366.  
  2367.  
  2368.  
  2369.  
  2370.  
  2371.  
  2372.  
  2373.  
  2374.  
  2375.  
  2376.  
  2377.  
  2378.  
  2379.  
  2380.  
  2381.  
  2382.  
  2383.  
  2384.  
  2385.  
  2386.  
  2387.  
  2388.  
  2389.  
  2390.  
  2391.  
  2392.  
  2393.  
  2394.  
  2395.  
  2396.  
  2397.  
  2398.  
  2399.  
  2400.  
  2401.  
  2402.  
  2403.  
  2404.                                      Page 32
  2405.  
  2406.                                                               Getting Started
  2407.  
  2408.  
  2409.             
  2410.  
  2411.  
  2412.                                    User Guide
  2413.  
  2414.  
  2415.  
  2416.  
  2417.             Getting Started
  2418.  
  2419.                Starting Hamilton  C shell  is simple:  select it from
  2420.             the Start Programs window or the Program Selector or type
  2421.             ``csh'' as  a command  to cmd.exe.    After  the  initial
  2422.             greeting, you'll  see the  first prompt:  (The underscore
  2423.             is meant to be the cursor.)
  2424.  
  2425.                  Hamilton C shell(tm) Release 2.2
  2426.                  Copyright (c) 1988-1993 by Hamilton Laboratories.
  2427.                  All rights reserved.
  2428.                  1 D% _
  2429.  
  2430.                This tells  you that it will remember what you type as
  2431.             command number  1 and  that your current drive is D.  The
  2432.             ``%'' is  traditional; rather  like the   ``>''  for DOS.
  2433.             Naturally, you  can change your prompt if you want, to be
  2434.             anything you  like.   For example,  to get  a prompt that
  2435.             looks like one you might get from cmd.exe+:
  2436.  
  2437.                  1 D% set prompt1 = '[$upper(cwd)] '
  2438.                  [D:\DOUG] _
  2439.  
  2440.                This works  by taking  the value  of the  cwd (current
  2441.             working directory)  variable, turning  it to  upper  case
  2442.             using one of the built-in procedures and pasting left and
  2443.             right brackets around it.  The value is recalculated each
  2444.             time a  prompt is  given, so it always displays an up-to-
  2445.             date value.   (Lists  of all  the built-in  variables and
  2446.             procedures are given in later sections.)
  2447.  
  2448.                To set it back:
  2449.  
  2450.                  [D:\DOUG] set prompt1 = '$@ $CDISK% '
  2451.                  3 D% _
  2452.  
  2453.  
  2454.  
  2455.             ____________________
  2456.             + We introduce  this is  as the  first example  with some
  2457.               trepidation:   the prompt  seems to  be the first thing
  2458.               people want  to change.   But it can also be one of the
  2459.               more daunting  projects   if  you're  getting  started.
  2460.               This example is offered more in the spirit of assurance
  2461.               that, with  a little  experience, the prompt can be set
  2462.               to anything you like.
  2463.  
  2464.  
  2465.  
  2466.                                      Page 33
  2467.  
  2468.      Getting Started
  2469.  
  2470.  
  2471.             Basic Statements
  2472.  
  2473.                Generally speaking,  whatever commands  you might have
  2474.             typed into  cmd.exe  will  still  work  here.    Even  an
  2475.             ``internal'' cmd.exe function like dir works:
  2476.  
  2477.                  3 D% dir
  2478.                  
  2479.                   The volume label in drive D is USER.
  2480.                   Directory of D:\DOUG\SH\DOCS\SCRIPT\HELLO
  2481.                  
  2482.                  .            <DIR>      2-23-89   2:13p
  2483.                  ..           <DIR>      2-23-89   2:13p
  2484.                  HELLO    C         72   2-23-89  12:56p
  2485.                  HELLO    EXE     7731   2-23-89  12:57p
  2486.                  MEMOS        <DIR>      2-23-89   1:46p
  2487.                       5 File(s)   1581056 bytes free
  2488.                  4 D% _
  2489.  
  2490.                If the command you type refers to a .cmd batch file or
  2491.             a cmd.exe  internal function,  Hamilton C shell passes it
  2492.             to  a  child  process  running  cmd.exe  for  evaluation.
  2493.             (cmd.exe's  built-in   functions  are   intercepted  with
  2494.             aliases defined  in your  startup.csh file.)   Everything
  2495.             else is  evaluated directly  by Hamilton  C shell.    For
  2496.             example, if  you type  the name  of  an  .exe  file,  the
  2497.             appropriate DosExecPgm(  ) or  DosStartSession( ) call to
  2498.             the OS/2 kernel or CreateProcess( ) call to the NT kernel
  2499.             to start that program will be done directly by Hamilton C
  2500.             shell.
  2501.  
  2502.                A bit-mapped  hash mechanism  is used so that when you
  2503.             type the  name of a command, the shell zeroes right in on
  2504.             file you  mean.   It doesn't  have to  check  every  path
  2505.             directory for  every possible  extension.   Naturally, if
  2506.             you  type   a  command  that  doesn't  exist,  the  shell
  2507.             complains:
  2508.  
  2509.                  4 D% zork
  2510.                  csh:  Couldn't find an executable file named 'zork'.
  2511.  
  2512.                By being  more than  merely a  ``wrapper''  around  an
  2513.             existing  command   processor,  several   advantages  are
  2514.             created:     (1)  performance   is  understandably   (and
  2515.             visibly!) much higher and (2) limitations on command line
  2516.             lengths, etc.,  become the  relatively generous limits of
  2517.             OS/2 and  NT,  rather  than  the  restrictive  limits  of
  2518.             cmd.exe.
  2519.  
  2520.  
  2521.  
  2522.             Customizing the Screen Colors
  2523.  
  2524.  
  2525.  
  2526.  
  2527.  
  2528.                                      Page 34
  2529.  
  2530.                                                               Getting Started
  2531.  
  2532.  
  2533.                The  C   shell's  default   screen  colors  are  white
  2534.             characters on a black background.  Highlighting and color
  2535.             are used  to make some things (special files, etc.) stand
  2536.             out.   All the use of color or highlighting is completely
  2537.             customizable.   You can  choose anything  you like.   The
  2538.             chapter on customization will go into this in detail, but
  2539.             for now, let's suppose we'd simply like to pick something
  2540.             a little  easier on  the eyes, like white characters on a
  2541.             blue background:
  2542.  
  2543.                  5 D% setenv COLORS = white on blue
  2544.  
  2545.  
  2546.  
  2547.             Command Line Editing
  2548.  
  2549.                With command  line editing,  you'll notice immediately
  2550.             how much  easier it is do things quickly without a lot of
  2551.             retyping.  As you try the examples, notice how the arrow,
  2552.             insert, delete,  home, end  and other keys can be used to
  2553.             recall previous  commands or make changes anywhere on the
  2554.             line.
  2555.  
  2556.                Command line  editing is  like  having  a  full-screen
  2557.             editor pasted  onto the  front end  of the  shell.    Key
  2558.             bindings are  intuitive and  follow accepted conventions.
  2559.             You can create enormous commands that stretch over screen
  2560.             after  screen  and  move  around  with  the  arrow  keys,
  2561.             inserting or  deleting anywhere.   Watch  changes  ripple
  2562.             almost instantly  down even  an entire screenful of text.
  2563.             We think you'll find our command line editing superior to
  2564.             anything you've seen or used elsewhere.
  2565.  
  2566.                The basic key assignments are:
  2567.  
  2568.                <Insert>       Toggle between insert and overstrike
  2569.                               modes.  (The cursor is thicker when
  2570.                               you're inserting.)
  2571.  
  2572.                <Home>   <End> Beginning/end of command line.
  2573.  
  2574.                <Left>   <Right> One character left/right.
  2575.  
  2576.                <Up>   <Down>  Up/down one command in the history
  2577.                               list.
  2578.  
  2579.                Pressing Ctrl  with the  arrow keys  lets you  move by
  2580.             words or  lines.   Pressing Alt instead does word or line
  2581.             deletion.   (The convention we follow is that the Alt key
  2582.             is a little ``more powerful'' than the Ctrl key.)
  2583.  
  2584.                What you  last deleted  is kept  in a scrap buffer and
  2585.             can be  pasted back  elsewhere.   To paste something from
  2586.  
  2587.  
  2588.  
  2589.  
  2590.                                      Page 35
  2591.  
  2592.      Getting Started
  2593.  
  2594.  
  2595.             the scrap  buffer back  into the  command line,  move the
  2596.             cursor to where you want it done and press:
  2597.  
  2598.                Ctrl-<Insert>  Paste one word at a time.
  2599.  
  2600.                Alt-<Insert>   Paste the whole thing.
  2601.  
  2602.  
  2603.  
  2604.             Command Completion
  2605.  
  2606.                In  addition  to  backing  up  through  your  previous
  2607.             commands one at a time with <Up> and <Down>, you can also
  2608.             ask  the  shell  to  search  back  through  any  previous
  2609.             commands you've  typed for  the last  command that either
  2610.             started with  or contained the characters in the previous
  2611.             word.
  2612.  
  2613.                Ctrl-<Enter>   means ``look for a command that started
  2614.                               with ...,'' and
  2615.  
  2616.                Alt-<Enter>    (again, a little ``stronger'') means
  2617.                               ``look for a command that contained the
  2618.                               string anywhere.''  (On NT, it's
  2619.                               necessary to type Ctrl-Shift-<Enter>
  2620.                               because Alt-<Enter> is grabbed by the
  2621.                               system to mean switch to full-screen.)
  2622.  
  2623.                Repeatedly pressing  these keys  cycles up through all
  2624.             the matching  commands you've  previously typed.  Command
  2625.             completion uses something called the history mechanism to
  2626.             recall commands  you've previously  typed.   Later, we'll
  2627.             devote a  whole chapter to some of the more advanced uses
  2628.             of history.
  2629.  
  2630.  
  2631.  
  2632.  
  2633.  
  2634.  
  2635.  
  2636.  
  2637.  
  2638.  
  2639.  
  2640.  
  2641.  
  2642.  
  2643.  
  2644.  
  2645.  
  2646.  
  2647.  
  2648.  
  2649.  
  2650.  
  2651.  
  2652.                                      Page 36
  2653.  
  2654.                                                               Getting Started
  2655.  
  2656.  
  2657.             Filename Completion
  2658.  
  2659.                Filename completion  is another  ``creature comfort:''
  2660.             you type  just a fragment of a filename and let the shell
  2661.             fill in the rest.  There are three variations:  using the
  2662.             F key  for basic  filename completion,  the D  key if you
  2663.             want all  the duplicates  listed  and  the  Tab  key  for
  2664.             walking one-by-one through the list of matches.
  2665.  
  2666.                Alt-F or Ctrl-F  Filename completion.
  2667.  
  2668.                               Look for a filename that starts with
  2669.                               preceding characters.  If it matches a
  2670.                               single file, fill in the rest of the
  2671.                               name.
  2672.  
  2673.                               If more than one file matched, show the
  2674.                               part that was the same for all,
  2675.                               highlighted in green.  (Bright red
  2676.                               means there were no matches at all.)
  2677.  
  2678.                Alt-D or Ctrl-D  Duplicate completions.
  2679.  
  2680.                               Show any/all matching filenames, one
  2681.                               after the other with spaces between.
  2682.  
  2683.                <Tab>          Next match.
  2684.  
  2685.                               Show the new match in the list of
  2686.                               filenames that match the wildcard,
  2687.                               replacing the previous match.  After
  2688.                               the last match, put the original string
  2689.                               back up, highlighting it in bright red,
  2690.                               then continue cycling through the list
  2691.                               again.
  2692.  
  2693.                Shift-<Tab>    Previous match.
  2694.  
  2695.                               Same as the <Tab> key, but rotate
  2696.                               backward through the list of matches.
  2697.  
  2698.                (Since  <Tab>   is  normally  bound  to  the  filename
  2699.             completion function,  the regular  tab character is typed
  2700.             instead as Ctrl-<Tab>.  If you'd prefer to have the <Tab>
  2701.             key be  the  regular  tab  character  and  Ctrl-<Tab>  be
  2702.             filename completion,  invoke the  C  shell  with  the  -T
  2703.             option.)
  2704.  
  2705.                Filename completion  is done with wildcarding, pasting
  2706.             an ``*''  onto the  end of  the previous  word  and  then
  2707.             looking for  any matches.   Unlike  cmd.exe,  Hamilton  C
  2708.             shell does  any wildcarding  before executing the command
  2709.             you type.   It  uses a  powerful recursive  pattern match
  2710.             algorithm that  guarantees sensible  matches even  if you
  2711.  
  2712.  
  2713.  
  2714.                                      Page 37
  2715.  
  2716.      Getting Started
  2717.  
  2718.  
  2719.             type a  very complex pattern.  Wildcarding is the subject
  2720.             of a whole chapter up ahead.
  2721.  
  2722.  
  2723.  
  2724.             The Tour Begins Here
  2725.  
  2726.                The   following   chapters   introduce   the   various
  2727.             facilities Hamilton  C shell provides, starting with some
  2728.             of its  basic vocabulary:  the simple utilities that come
  2729.             with it.
  2730.  
  2731.                Following discussion shifts to the intrinsic, internal
  2732.             functions provided by the shell itself:  i/o redirection,
  2733.             pipes and command substitution; the history mechanism and
  2734.             wildcarding.
  2735.  
  2736.                Intermediate  level   discussion  follows,  describing
  2737.             expressions, variables  and aliases  and the  editing and
  2738.             quoting facilities.   The  process and  thread scheduling
  2739.             mechanism is  described, outlining how an activity can be
  2740.             placed in the background.
  2741.  
  2742.                The tour will then cross the threshold from discussion
  2743.             of individual  statements to  discussion of structures of
  2744.             statements.   Structures  for  iteration  and  condition-
  2745.             testing and procedural abstraction will be introduced.
  2746.  
  2747.                Finally, we'll  wrap up  with  discussion  of  how  to
  2748.             customize the  shell together  with a  section  detailing
  2749.             specific compatibility  issues between  the Hamilton  and
  2750.             original Berkeley C shells.
  2751.  
  2752.  
  2753.  
  2754.  
  2755.  
  2756.  
  2757.  
  2758.  
  2759.  
  2760.  
  2761.  
  2762.  
  2763.  
  2764.  
  2765.  
  2766.  
  2767.  
  2768.  
  2769.  
  2770.  
  2771.  
  2772.  
  2773.  
  2774.  
  2775.  
  2776.                                      Page 38
  2777.  
  2778.                                                               Getting Started
  2779.  
  2780.  
  2781.                
  2782.  
  2783.  
  2784.  
  2785.  
  2786.  
  2787.  
  2788.  
  2789.  
  2790.  
  2791.  
  2792.  
  2793.  
  2794.  
  2795.  
  2796.  
  2797.  
  2798.  
  2799.  
  2800.  
  2801.  
  2802.  
  2803.  
  2804.  
  2805.  
  2806.  
  2807.  
  2808.  
  2809.  
  2810.  
  2811.  
  2812.  
  2813.  
  2814.  
  2815.  
  2816.  
  2817.  
  2818.  
  2819.  
  2820.  
  2821.  
  2822.  
  2823.  
  2824.  
  2825.  
  2826.  
  2827.  
  2828.  
  2829.  
  2830.  
  2831.  
  2832.  
  2833.  
  2834.  
  2835.  
  2836.  
  2837.  
  2838.                                      Page 39
  2839.  
  2840.      Utilities
  2841.  
  2842.  
  2843.             
  2844.  
  2845.  
  2846.                                   The Utilities
  2847.  
  2848.  
  2849.                Hamilton C  shell comes  with a  lot of utilities that
  2850.             form some  of its  vocabulary.   They do  small, but oft-
  2851.             needed functions,  often  in  a  novel,  faster  or  more
  2852.             convenient way  than you'd find in ``plain vanilla'' OS/2
  2853.             or NT.   This  section provides  a quick  tour, outlining
  2854.             some of the capabilities and conventions.
  2855.  
  2856.  
  2857.  
  2858.             ls:  List files
  2859.  
  2860.                ls is a somewhat nicer way to list a directory:
  2861.  
  2862.                  6 D% ls
  2863.                  memos      hello.c    hello.exe  sysstuff
  2864.  
  2865.             Subdirectories are  highlighted (shown here in bold.)  If
  2866.             a file  or directory  has the  system bit set, it's still
  2867.             listed, displayed  in  green  (shown  here  in  italic.)+
  2868.             Normally, ls  lists everything  in lower  case for better
  2869.             readability.  In long format:
  2870.  
  2871.                  7 D% ls -l
  2872.                  D----  Feb 23  13:46          -  memos
  2873.                  ---A-  Feb 23  12:56         72  hello.c
  2874.                  ---A-  Feb 23  12:57       7731  hello.exe
  2875.                  -S-A-  Feb 23  13:22         15  sysstuff
  2876.  
  2877.                Conventionally, ls  lists things  alphabetically, with
  2878.             directories ahead  of files.  There might be hidden files
  2879.             or directories, but to see them you have to ask:
  2880.  
  2881.                  8 D% ls +H
  2882.                  memos      hello.c    hello.exe  hiding     sysstuff
  2883.  
  2884.  
  2885.  
  2886.             Conventions
  2887.  
  2888.                To find  out how  any of  the utilities work, just use
  2889.             the -h option.  For example,
  2890.  
  2891.                  9 D% ls -h
  2892.             ____________________
  2893.             + All our  examples will be given in terms of the default
  2894.               screen colors.   But  these are  easily changed to your
  2895.               own preferences.   See  the chapter on customization or
  2896.               the colors.csh script file in the samples directory.
  2897.  
  2898.  
  2899.  
  2900.                                      Page 40
  2901.  
  2902.                                                                     Utilities
  2903.  
  2904.  
  2905.             tells about  options for  more detailed listings, sorting
  2906.             the list by date or by size, selecting only certain types
  2907.             of files,  etc.   ls is  a read-only  activity; it  never
  2908.             makes any  changes to  the file system.  Lists are always
  2909.             sorted in  memory; its  speed and  flexibility completely
  2910.             obsolete  the  old  (and  dangerous)  ``directory  sort''
  2911.             utilities popular on DOS.
  2912.  
  2913.                The  names   of  the   utilities  were  chosen  to  be
  2914.             consistent with  the names  of similar functions on UNIX,
  2915.             where they  provided  much  of  the  vocabularly  of  the
  2916.             original UNIX  C shell.   But  changing  the  name  of  a
  2917.             utility  is   a  simple   matter:     just   rename   the
  2918.             corresponding .exe file or, better still, create an alias
  2919.             (discussed later.)
  2920.  
  2921.                By convention,  the utilities  expect options  to come
  2922.             ahead of  any files  you  specify.    Options  are  case-
  2923.             sensitive.   We've tried  to  use  mnemonic  letters  for
  2924.             options (e.g.,  h for help) and to use the same letter to
  2925.             mean the  same thing  across related utilities; achieving
  2926.             that is  simply  more  feasible  with  52,  not  just  26
  2927.             characters to choose from.
  2928.  
  2929.                Our examples  generally show  options introduced  with
  2930.             ``-'', but  you could  equally well  follow the DOS-style
  2931.             convention of  using ``/''  if you prefer.  If indeed you
  2932.             want only  ``-'' or  only ``/''  interpreted as an option
  2933.             character,  this   can  be   set  with   the  SWITCHCHARS
  2934.             environmental variable,  which can be set either from the
  2935.             C shell  or from your config.sys file on OS/2 or from the
  2936.             Control Panel  on NT.  Sadly, it won't have any effect on
  2937.             the standard  OS/2 or NT commands like dir or xcopy or on
  2938.             applications you  purchase elsewhere, but it will work on
  2939.             all the commands supplied with the C shell.  For example,
  2940.             to have only ``-'' recognized as an option character, you
  2941.             might type this into the C shell:
  2942.  
  2943.                  10 D% setenv SWITCHCHARS = -
  2944.  
  2945.             or put  this into  config.sys (rebooting  to make it take
  2946.             effect):
  2947.  
  2948.                  set SWITCHCHARS=-
  2949.  
  2950.                You can  type options  in any  order (except where one
  2951.             overrides another,  in which  case the  last  setting  is
  2952.             used) and you group them together or type them separately
  2953.             as you  choose.   For example, ``ls -L -d -w'' is exactly
  2954.             the same  as ``ls -dwL''  and produces a very long format
  2955.             (very detailed)  list of the current directory, sorted by
  2956.             date (newest  ones last),  with sizes  of any directories
  2957.             filled in  by walking  down through  the directory  tree,
  2958.             adding up all the sizes of all the files found there.
  2959.  
  2960.  
  2961.  
  2962.                                      Page 41
  2963.  
  2964.      Utilities
  2965.  
  2966.  
  2967.                You can  always unambiguously  end  the  options  with
  2968.             ``--'' in  case you have a filename or an argument string
  2969.             that begins  with one  of option-introducing  characters.
  2970.             Also, since the shell does the wildcard expansion, it's a
  2971.             bit more  convenient and faster for the utilities to look
  2972.             for any options right at the beginning of what could be a
  2973.             very long  list  (up  to  64  kilobytes  under  OS/2;  32
  2974.             kilobytes under  NT) of  filenames or  other command-line
  2975.             text.
  2976.  
  2977.                We'll always  follow the  OS/2 and  NT  convention  of
  2978.             using ``\''  in filenames  in this  book and we generally
  2979.             advise that  you do  too, not so much because the C shell
  2980.             cares but  because so  much other  OS/2 and  NT  software
  2981.             does.   To some  fair degree,  it's a  case of  ``when in
  2982.             Rome, doing  as the  Romans do.''   But  if you really do
  2983.             prefer, you  can generally use ``/'' with the C shell and
  2984.             all the  utilities.   Do remember,  however, that  if you
  2985.             type a filename starting with ``/'' to mean the root, you
  2986.             have to be careful that it can't be confused as the start
  2987.             of an  option.  (This is a good use for the ``--'' option
  2988.             or the SWITCHCHARS variable.)
  2989.  
  2990.  
  2991.  
  2992.  
  2993.  
  2994.  
  2995.  
  2996.  
  2997.  
  2998.  
  2999.  
  3000.  
  3001.  
  3002.  
  3003.  
  3004.  
  3005.  
  3006.  
  3007.  
  3008.  
  3009.  
  3010.  
  3011.  
  3012.  
  3013.  
  3014.  
  3015.  
  3016.  
  3017.  
  3018.  
  3019.  
  3020.  
  3021.  
  3022.  
  3023.  
  3024.                                      Page 42
  3025.  
  3026.                                                                     Utilities
  3027.  
  3028.  
  3029.             echo
  3030.  
  3031.                echo is a little different than the vanilla OS/2 or NT
  3032.             echo.   It  does  only  one  thing:  it  prints  whatever
  3033.             arguments words  you give  it; there's no echo on or echo
  3034.             off-style status  reporting function.   But it does offer
  3035.             much finer control over what gets printed:  you can write
  3036.             binary values,  choose not to append a new line and write
  3037.             to stderr instead stdout.
  3038.  
  3039.                Here's an  example where  the  ANSI  escape  sequences
  3040.             turning brightness  on and off are embedded into a string
  3041.             being echoed.   The  ANSI escape  character is octal 033;
  3042.             binary  values  or  special  characters  like  ``[''  are
  3043.             introduced by the ``^'' shell escape.
  3044.  
  3045.                  11 D% echo Have a ^033^[1mnice^033^[0m day.
  3046.                  Have a nice day.
  3047.  
  3048.                (Processing of  the ^  escape sequences is done by the
  3049.             shell before  any command ever sees it.  As a result, you
  3050.             can  use  escape  sequences  to  construct  command  line
  3051.             arguments for  any command;  this feature  is  introduced
  3052.             here only  because it  tends to  be most  often used with
  3053.             echo.)
  3054.  
  3055.  
  3056.  
  3057.             mv, cp and rm:  Move, copy and remove
  3058.  
  3059.                The mv  (move), cp  (copy) and rm (remove) trio allows
  3060.             files and directories to be treated as simple objects.
  3061.  
  3062.                mv will move either files or directories treating them
  3063.             simply as  objects, even  across disk  partitions.     In
  3064.             this example,  the two  hello files  are moved into a new
  3065.             directory,  illustrating   how  mv  understands  that  if
  3066.             there's a  many-to-one relationship,  the destination has
  3067.             to be a directory.
  3068.  
  3069.                  12 D% mv hello* hello
  3070.                  13 D% ls
  3071.                  hello        memos        sysstuff
  3072.                  14 D% ls hello
  3073.                  hello.c      hello.exe
  3074.  
  3075.                Similarly, cp   will  copy a  file or  even an  entire
  3076.             directory.   The copies  cp  produces  are  always  exact
  3077.  
  3078.  
  3079.  
  3080.  
  3081.  
  3082.  
  3083.  
  3084.  
  3085.  
  3086.                                      Page 43
  3087.  
  3088.      Utilities
  3089.  
  3090.  
  3091.             logical copies,  with correct  timestamps+  and attribute
  3092.             bits and including any hidden or system files.
  3093.  
  3094.                  15 D% cp hello newhello
  3095.                  16 D% ls
  3096.                  hello        memos        newhello     sysstuff
  3097.                  17 D% ls -l hello
  3098.                  ---A-  Feb 23  12:56         72  hello.c
  3099.                  ---A-  Feb 23  12:57       7731  hello.exe
  3100.                  18 D% ls -l newhello
  3101.                  ---A-  Feb 23  12:56         72  hello.c
  3102.                  ---A-  Feb 23  12:57       7731  hello.exe
  3103.  
  3104.             cp does not consider it an error to copy over an existing
  3105.             file unless  the file  about to  be overwritten  has  its
  3106.             read-only bit set.
  3107.  
  3108.                Finally, rm   can  be used to remove a file or even an
  3109.             entire directory.   But  it does  insist that you tell it
  3110.             you really  mean it  if you  ask to  remove  a  directory
  3111.             that's not  empty or  anything  that's  marked  with  the
  3112.             system bit.
  3113.  
  3114.                  19 D% rm sysstuff
  3115.                  rm:  Can't remove system file 'systuff' without -S
  3116.                  option.
  3117.                  20 D% rm -S sysstuff
  3118.                  21 D% ls
  3119.                  hello        memos        newhello
  3120.                  22 D% rm newhello
  3121.                  rm:  Can't remove non-empty directory 'newhello'
  3122.                  without -r option.
  3123.                  23 D% rm -r newhello
  3124.                  24 D% ls
  3125.                  hello        memos
  3126.  
  3127.                As you  can see from these examples, the general style
  3128.             of the  utilities is  fairly terse.   Like the proverbial
  3129.             Vermonter, they  don't say  anything unless  they've  got
  3130.             something to  say.   Even copying or removing a directory
  3131.             happens without fanfare as long as the appropriate ``yes,
  3132.             I really mean it'' options are supplied.
  3133.  
  3134.  
  3135.  
  3136.             more
  3137.  
  3138.                more is an especially fast browsing filter.  There are
  3139.             two ways  to use  more.   The first is in a pipeline, the
  3140.  
  3141.             ____________________
  3142.             + Files only  under OS/2 1.1.  New directories always get
  3143.               the current timestamp unless you're running OS/2 1.2 or
  3144.               later.
  3145.  
  3146.  
  3147.  
  3148.                                      Page 44
  3149.  
  3150.                                                                     Utilities
  3151.  
  3152.  
  3153.             way ``vanilla''  more might  be used when you suspect the
  3154.             data may be longer than a screenful:
  3155.  
  3156.                  25 D% ls -l c:\os2\bin | more
  3157.                  :
  3158.                  :
  3159.  
  3160.             If the output turns out to be less than a screenful, it's
  3161.             as though  you'd just typed the ls command by itself.  In
  3162.             fact, there's  not even a noticeable performance penalty.
  3163.             But if  it's more  than a  screenful, more switches to an
  3164.             interactive mode  where you can use the arrow keys, etc.,
  3165.             to browse up and down through the listing.
  3166.  
  3167.                more can also be used for browsing a list of the files
  3168.             you give it on the command line:
  3169.  
  3170.                  26 D% more *.c
  3171.  
  3172.                more incorporates  the Berkeley  notion  referred  to,
  3173.             tongue-in-cheek, as  ``more is  less+'':    it's  a  good
  3174.             paging filter  that lets  you go  forwards and backwards.
  3175.             It also  offers a  number of different ways of looking at
  3176.             or  searching  the  data  including  binary,  as  control
  3177.             characters, line-numbered,  etc.  Perhaps most important,
  3178.             it's fast.
  3179.  
  3180.                Part of  more's speed  comes from an internal cache of
  3181.             about 11K  characters of  text  coupled  to  an  indexing
  3182.             structure that  it builds  on the  fly as  it  reads  the
  3183.             input.   When you  move forward  or backward  within  the
  3184.             cache, screen  redraw rates  are the  limiting factor  in
  3185.             performance.  Outside of range of the cache, if the input
  3186.             is from  a disk file, the indexing structure, technically
  3187.             an ISAM, tells more how to seek to the new location.
  3188.  
  3189.                There is  also a  ``huge''  version  of  more,  called
  3190.             moreh,  that  was  compiled  in  large  model  and  while
  3191.             slightly slower, has the advantage of caching up to about
  3192.             4M characters.   moreh  can be  useful when speed is less
  3193.             important than  being able  to scroll  all the  way  back
  3194.             through a large amount of text coming through a pipe.
  3195.  
  3196.  
  3197.  
  3198.             touch
  3199.  
  3200.             ____________________
  3201.             + The story  is now  a part of computer folk history:  at
  3202.               first, more  only went forward.  Then someone created a
  3203.               filter that  went backwards, which he aptly named less.
  3204.               When later  versions of  Berkeley's  more  incorporated
  3205.               this feature, they were heralded by announcements that,
  3206.               finally, ``more was less.''
  3207.  
  3208.  
  3209.  
  3210.                                      Page 45
  3211.  
  3212.      Utilities
  3213.  
  3214.  
  3215.                touch lets  you change  the timestamps  of  individual
  3216.             files  or  directories+  or,  using  the  -r  (recursive)
  3217.             option, of everything in a whole directory tree.
  3218.  
  3219.                If the  desired timestamp  isn't given, touch uses the
  3220.             current time.    If  the  filename  doesn't  exist,  it's
  3221.             created as a zero-length file.
  3222.  
  3223.                  27 D% ls
  3224.                  hello        memos
  3225.                  28 D% touch zork
  3226.                  29 D% ls
  3227.                  hello        memos        zork
  3228.  
  3229.  
  3230.  
  3231.             chmod
  3232.  
  3233.                chmod lets  you set a file's attributes but leaves the
  3234.             timestamp alone.   Here  is an example, first setting the
  3235.             system bit  (making it  show up in green), then making it
  3236.             hidden:
  3237.  
  3238.                  30 D% chmod +S zork
  3239.                  31 D% ls
  3240.                  hello        memos        zork
  3241.                  32 D% chmod +H zork
  3242.                  33 D% ls
  3243.                  hello        memos
  3244.  
  3245.             Of course,  the file  is still there and you can continue
  3246.             to manipulate its attributes:
  3247.  
  3248.                  34 D% ls -l zork
  3249.                  -SHA-  Feb 23  13:16         0  zork
  3250.                  35 D% ls +a
  3251.                  .              hello          zork
  3252.                  ..             memos
  3253.                  36 D% chmod +R zork
  3254.                  37 D% ls -l zork
  3255.                  -SHAR  Feb 23  13:16         0  zork
  3256.  
  3257.                Many users  will find that a file's system bit is more
  3258.             useful than they'd thought before.  With chmod, it's easy
  3259.             to set  or clear  the bit and setting it doesn't make the
  3260.             file hidden.   Quite the contrary, ls makes it stands out
  3261.             in green.   Also,  a file  marked ``system''  is a little
  3262.             safer from accidental deletion or overwriting.  These are
  3263.             often convenient characteristics to attach a few specific
  3264.             ____________________
  3265.             + On an  OS/2 1.1 system, the kernel allows you to change
  3266.               the  timestamps   only  on   files,  not   directories.
  3267.               touch'ing a directory does nothing unless you use the -
  3268.               r option to recursively touch the directory's contents.
  3269.  
  3270.  
  3271.  
  3272.                                      Page 46
  3273.  
  3274.                                                                     Utilities
  3275.  
  3276.  
  3277.             files within  a large directory.  For example, the author
  3278.             tends to routinely mark make files within a C source code
  3279.             directory as ``system'' just so they'll stand out.
  3280.  
  3281.  
  3282.  
  3283.             du, vol and pwd
  3284.  
  3285.                du, vol  and pwd  provide quick snapshots of your disk
  3286.             partitions:   du tells how much of the partition is used;
  3287.             vol  displays  the  label;  and  pwd  shows  the  current
  3288.             directory on each partition.
  3289.  
  3290.                  38 D% du
  3291.                  c: 31.904 M Total = 29.465 M Used + 2.439 M ( 7.65%)
  3292.                  Free  root
  3293.                  d: 23.920 M Total = 22.438 M Used + 1.482 M ( 6.20%)
  3294.                  Free  user
  3295.                  e: 13.957 M Total =  8.520 M Used + 5.438 M (38.96%)
  3296.                  Free  misc
  3297.                  39 D% pwd
  3298.                  c:\os2\include
  3299.                  d:\doug\sh\docs
  3300.                  e:\tmp
  3301.                  40 D% vol
  3302.                  c:  Jan 24  22:32:10  1988   root
  3303.                  d:  Nov 27  20:34:58  1988   user
  3304.                  e:  Jan 17  17:12:20  1988   misc
  3305.  
  3306.                A common  convention observed by the utilities is that
  3307.             if one  entry on  a list  is more current or special than
  3308.             the others,  it's highlighted.   du,  vol  and  pwd  each
  3309.             highlight the entry describing the current disk.
  3310.  
  3311.                For the  benefit of those who have lots of partitions,
  3312.             some of  which they  don't want to bother listing all the
  3313.             time, du,  vol and pwd look for a DRIVEMASK environmental
  3314.             variable which can be used to mask off just the drive you
  3315.             want.   This is  especially useful  for excluding  drives
  3316.             that take  removable media;  if they're  empty, they  can
  3317.             waste a  lot of time trying to read a diskette that's not
  3318.             there.
  3319.  
  3320.  
  3321.  
  3322.             dirs, pushd, popd and rotd
  3323.  
  3324.                The shell  provides a  built-in mechanism  for keeping
  3325.             several directories  ``handy.''   This mechanism  is  the
  3326.             directory stack,  which always  contains a list of fully-
  3327.             qualified directory  pathnames with the current directory
  3328.             at the  top.   You can  display the  list with  the  dirs
  3329.             command:
  3330.  
  3331.  
  3332.  
  3333.  
  3334.                                      Page 47
  3335.  
  3336.      Utilities
  3337.  
  3338.  
  3339.                  41 D% dirs
  3340.                  d:\doug\sh\docs
  3341.  
  3342.                Initially  the   list  contains   only  your   current
  3343.             directory.   When you  push a  new directory on the stack
  3344.             with pushd,  that  becomes  your  new  current  disk  and
  3345.             current directory.   pushd  also  reports  the  resulting
  3346.             stack contents.
  3347.  
  3348.                  42 D% pushd c:
  3349.                  c:\os2\include
  3350.                  d:\doug\sh\docs
  3351.                  43 C% pushd e:
  3352.                  e:\tmp
  3353.                  c:\os2\include
  3354.                  d:\doug\sh\docs
  3355.  
  3356.                Calling pushd without any arguments just swaps the top
  3357.             two directories:
  3358.  
  3359.                  44 E% pushd
  3360.                  c:\os2\include
  3361.                  e:\tmp
  3362.                  d:\doug\sh\docs
  3363.  
  3364.                Popping elements  off the  stack is  done  with  popd,
  3365.             which also reports the resulting stack.
  3366.  
  3367.                  45 C% popd
  3368.                  e:\tmp
  3369.                  d:\doug\sh\docs
  3370.  
  3371.                The stack  can also be rotated with rotd.  (We'll push
  3372.             another directory  first so  we can  see that rotation is
  3373.             upward, with  the top  item going  to the  bottom of  the
  3374.             stack.)
  3375.  
  3376.                  46 E% pushd \
  3377.                  e:\
  3378.                  e:\tmp
  3379.                  d:\doug\sh\docs
  3380.                  47 E% rotd
  3381.                  e:\tmp
  3382.                  d:\doug\sh\docs
  3383.                  e:\
  3384.  
  3385.                You can pop multiple directory entries at once, but if
  3386.             you ask to pop more than exist, you'll get a message:
  3387.  
  3388.                  48 E% popd 5
  3389.                  csh:  The built-in popd command can only accept a
  3390.                  integer argument n, where n > 0 && n < number of
  3391.                  elements on the directory stack.  The default for n
  3392.                  is 1.
  3393.  
  3394.  
  3395.  
  3396.                                      Page 48
  3397.  
  3398.                                                                     Utilities
  3399.  
  3400.  
  3401.                  49 E% popd
  3402.                  d:\doug\sh\docs
  3403.                  e:\
  3404.  
  3405.  
  3406.  
  3407.             fgrep and grep
  3408.  
  3409.                fgrep and  grep  are  fast  string  search  utilities.
  3410.             Their  names   and  the  regular  expression  syntax  are
  3411.             traditional; it's an accepted standard and we've followed
  3412.             it.
  3413.  
  3414.                 fgrep and grep are used to scan through long lists of
  3415.             files or filter data coming through a pipe for strings or
  3416.             patterns you  specify.   They'll quickly  report all  the
  3417.             matching lines.   If  you like,  you can get more or less
  3418.             detail in  the output,  e.g., have  line numbers shown or
  3419.             just get a total count of all the matches.
  3420.  
  3421.                fgrep and  grep both  have the  ability to  look for a
  3422.             large number  of patterns in parallel (using the -s or -f
  3423.             options)   with   almost   no   discernable   performance
  3424.             degredation.   They're very  fast.   Both precompile  and
  3425.             optimize their  search patterns,  use direct  kernel  api
  3426.             calls for  all  i/o  and  use  a  very  high  performance
  3427.             buffering structure  to allow  extremely fast scanning of
  3428.             large amounts of data.
  3429.  
  3430.  
  3431.  
  3432.             fgrep
  3433.  
  3434.                fgrep is  the simpler  and slightly  faster of the two
  3435.             search utilities.    It  does  a  simple  string  compare
  3436.             between the  string you're looking for and the characters
  3437.             on each  line.  If the search string is found anywhere on
  3438.             the line,  it's a  match.   There are  some  options  for
  3439.             ignoring  differences  in  upper-/lower-case  or  in  the
  3440.             amount of white space (spaces and tabs) between words but
  3441.             mostly it's quite simple comparison.
  3442.  
  3443.                Here's an  example of  using fgrep  to search  a  very
  3444.             simple personal phone directory where each record is just
  3445.             a line  of text and we'll search it .  (Later we'll learn
  3446.             how to  package things like this up into aliases or shell
  3447.             procedures  so   you  can  call  them  with  just  a  few
  3448.             keystrokes.)
  3449.  
  3450.                  50 D% fgrep -i doctor \phone
  3451.                  Doctor James Gardner    508-999-0000  12 Canton St
  3452.                  Doctor Karen Strickland 508-721-1223  N.E. Medical
  3453.                  Offices
  3454.  
  3455.  
  3456.  
  3457.  
  3458.                                      Page 49
  3459.  
  3460.      Utilities
  3461.  
  3462.  
  3463.             grep
  3464.  
  3465.                grep  looks   for  special   patterns  called  regular
  3466.             expressions, which are similar to (but slightly different
  3467.             from) filename  wildcarding.   The grammar  is recursive,
  3468.             meaning  a  regular  expression  to  be  matched  can  be
  3469.             written,  in   turn,  as   a  nested  series  of  regular
  3470.             expressions:
  3471.  
  3472.                c      Any ordinary character matches itself.
  3473.                \c     Match the literal character c.
  3474.                ^      Beginning of line.
  3475.                $      End of line.
  3476.                .      Match any single character.
  3477.                [...]  Match any single character in the list.
  3478.                [^...] Match any single character not in the list.
  3479.                \n     Match whatever  literal text  the  n'th  tagged
  3480.                       \(...\) expression matched.
  3481.                r*     Match zero or more occurrences of r.
  3482.                r1r2   Match expression r1 followed by r2.
  3483.                \(r\)  Tagged regular  expression.   Match the pattern
  3484.                       inside the  \(...\), and  remember the  literal
  3485.                       text that matched.
  3486.                At the  lowest layer,  you give  a character or set of
  3487.             characters to  be matched anchored, if you want, to match
  3488.             just the  beginning or  just the  end of  a line.  At the
  3489.             next layer, the ``*'' character lets you match a variable
  3490.             number of repetitions of a pattern.
  3491.  
  3492.                When you  type a  regular expression  on  the  command
  3493.             line, keep  in mind:   (1)  Many of  the characters  have
  3494.             special meaning  to the  C shell  and have  to be  inside
  3495.             quotes.  (2) You have to type two ``^'s'' to get just one
  3496.             because ``^''  is the  shell's literal  escape character.
  3497.             (3) ``*''  is a  postfix operator.   It  operates on  the
  3498.             preceding regular  expression; by  itself, it  is  not  a
  3499.             ``match zero  or more  characters'' wildcard character as
  3500.             you may be used to with filenames.
  3501.  
  3502.                Here's an  example of searching through all the source
  3503.             code for a large application, looking for all occurrences
  3504.             of lines  that begin  with ``statement''  followed  by  a
  3505.             ``y'' somewhere  on the line and showing the line numbers
  3506.             of any  matches.   (The -s option tells pushd and popd to
  3507.             work silently.)
  3508.  
  3509.                  51 D% pushd -s ~\sh
  3510.                  52 D% grep -n '^^statement.*y' *.c
  3511.                  allocate.c:418:statement_obj
  3512.                  *allocate_statement(size, type)
  3513.                  53 D% popd -s
  3514.  
  3515.  
  3516.  
  3517.  
  3518.  
  3519.  
  3520.                                      Page 50
  3521.  
  3522.                                                                     Utilities
  3523.  
  3524.  
  3525.             sed
  3526.  
  3527.                sed is  a stream  editor.   Just as you might think of
  3528.             using a  regular editor  to  edit  a  file,  deleting  or
  3529.             inserting lines,  doing search/replace  operations, etc.,
  3530.             sed lets you edit a stream of data:  individual lines are
  3531.             read from  stdin, edited according to the script you give
  3532.             and written  to stdout.   A  very simple  sort of  script
  3533.             might be  given right  on the  command line.    Here's  a
  3534.             simple search/replace:
  3535.  
  3536.                  54 D% echo hello world | sed s/world/everybody/
  3537.                  hello everybody
  3538.  
  3539.                sed uses  the same  regular expressions  used by grep.
  3540.             It's possible  to pick  up pieces  of the input as tagged
  3541.             expressions and  move them  around.  In this example, the
  3542.             two strings  on either side of the space are tagged, then
  3543.             swapped   around.      Quotes   are   used   around   the
  3544.             search/replace command  so the  C shell  will treat it as
  3545.             one  long   literal  string   to  be   passed   to   sed.
  3546.             (Parentheses, spaces and asterisks otherwise have special
  3547.             meaning.)   Notice how the ``*'' construct, meaning match
  3548.             zero  or   more  occurrences  actually  matches  as  many
  3549.             repetitions as possible.
  3550.  
  3551.                  55 D% echo hello world | sed 's/\(.*\) \(.*\)/\2
  3552.                  \1/'
  3553.                  world hello
  3554.  
  3555.                For more  complex operations,  sed offers a wide array
  3556.             of operators  including even  conditional branches  and a
  3557.             hold buffer  where a string can be saved temporarily from
  3558.             one line  to the  next.  If your script is very long, the
  3559.             -f option lets you specify it in a file.
  3560.  
  3561.  
  3562.  
  3563.             diff
  3564.  
  3565.                diff is  an extremely  fast and  flexible utility  for
  3566.             quickly comparing  ascii files,  looking for differences.
  3567.             In the  simplest form,  you simply  give it two filenames
  3568.             corresponding to  the old  and new versions and let it go
  3569.             to work,  reporting sections  that have  been deleted  or
  3570.             added in  a  traditional  format.    For  example,  as  a
  3571.             software developer, I might use it to compare old and new
  3572.             versions of a C program:
  3573.  
  3574.                  56 D% diff archive\parse.c parse.c
  3575.                  1493 c 1493
  3576.                  <          d->inline_cnt = src->inline_cnt++;
  3577.                  ---
  3578.                  >          d->inline_cnt = ++src->inline_cnt;
  3579.  
  3580.  
  3581.  
  3582.                                      Page 51
  3583.  
  3584.      Utilities
  3585.  
  3586.  
  3587.             Each change  is reported  in terms  of the line number or
  3588.             range in  the old  version,  whether  it's  an  addition,
  3589.             change or  deletion, the  line numbers in the new version
  3590.             and then  the affected lines from each file, separated by
  3591.             a line of ``---''.
  3592.  
  3593.                diff supports  the traditional  options  for  ignoring
  3594.             differences in  upper-/lower-case or  in  the  amount  of
  3595.             white space on the line, for recursively comparing entire
  3596.             directory trees of files, etc.
  3597.  
  3598.                One of  diff's most novel features is its ability with
  3599.             the -!  option to  generate a  merged listing  where text
  3600.             that's deleted  is shown  in red,  new text  is shown  in
  3601.             green and  the rest is displayed normally.  This makes it
  3602.             extremely easy  to view your changes in context.  (To use
  3603.             this option,  remember that  ``!'' is a special character
  3604.             to the  shell; type  it at  the end of the option list so
  3605.             there'll be a space following.)
  3606.  
  3607.  
  3608.  
  3609.             head and tail
  3610.  
  3611.                head and  tail are  used to  display just the first or
  3612.             last few  lines or  characters of a file.  Normally, they
  3613.             expand any  tabs into  spaces so you don't need to filter
  3614.             them through more.
  3615.  
  3616.                tail is  particularly interesting.  If all you want is
  3617.             the end  of a  very large  file, tail  doesn't waste time
  3618.             reading the whole file from start to finish.  Instead, it
  3619.             jumps right  to the  end and  reads it backwards!  If the
  3620.             file is  truly large  (on the order of several megabytes)
  3621.             and all you want is a little bit off the end, this is the
  3622.             difference between  chugging along  for  several  seconds
  3623.             versus getting an almost instantaneous response.
  3624.  
  3625.                tail also  has a -f follow option.  What that means is
  3626.             that when  it gets  to the  end of  file,  it  enters  an
  3627.             endless loop,  sleeping for  a second,  then waking up to
  3628.             see if  more has been added.  This is particularly useful
  3629.             if, e.g., you have an operation, say a large make, active
  3630.             in one window with its output redirected to a file.  From
  3631.             another window  you can  periodically  check  in  on  the
  3632.             progress by typing:
  3633.  
  3634.                  57 D% tail -f e:\tmp\make.log
  3635.                  :
  3636.                  ^C
  3637.  
  3638.             tail lets  you watch  lines get  added without  consuming
  3639.             much processor  resource (since  it sleeps  in the kernel
  3640.             most of  the time) so you can watch a background activity
  3641.  
  3642.  
  3643.  
  3644.                                      Page 52
  3645.  
  3646.                                                                     Utilities
  3647.  
  3648.  
  3649.             progress without affecting its performance.  After you've
  3650.             watched for  a while,  just type  ^C to interrupt and get
  3651.             out.   The interrupt  only goes  to the tail program; the
  3652.             application off  in the  background or  in another window
  3653.             creating the  file is  not affected  and will go on about
  3654.             its business  until you  come back once again to check on
  3655.             it.
  3656.  
  3657.  
  3658.  
  3659.             cut
  3660.  
  3661.                cut is  a simple filter for selecting out just certain
  3662.             fields or character positions of each line of input.  You
  3663.             choose what characters should be interpreted as the field
  3664.             delimiters and  which fields  should  be  copied  to  the
  3665.             output.   For example,  if you  kept your  phone book  in
  3666.             \phone, you might strip off just the first word from each
  3667.             line to get everyone's first names:
  3668.  
  3669.                  58 D% cut -f1 -d' ' \phone
  3670.                  Ed
  3671.                  Helen
  3672.                  Jack
  3673.                  Vickie
  3674.                  :
  3675.  
  3676.             The  -f  option  means  you  want  to  count  by  fields,
  3677.             selecting the  first field  and that  the delimiter  is a
  3678.             space character.  (Notice the quotes around the space.)
  3679.  
  3680.  
  3681.  
  3682.  
  3683.  
  3684.  
  3685.  
  3686.  
  3687.  
  3688.  
  3689.  
  3690.  
  3691.  
  3692.  
  3693.  
  3694.  
  3695.  
  3696.  
  3697.  
  3698.  
  3699.  
  3700.  
  3701.  
  3702.  
  3703.  
  3704.  
  3705.  
  3706.                                      Page 53
  3707.  
  3708.      Utilities
  3709.  
  3710.  
  3711.             split
  3712.  
  3713.                split lets  you break  up a  large file  into smaller,
  3714.             fixed-size  pieces   counting  either   by  lines  or  by
  3715.             characters.   Each of  the smaller  files it  creates are
  3716.             numbered, e.g., chunk.001, chunk.002, chunk.003, etc.
  3717.  
  3718.                One example  of where  you might use split might be if
  3719.             you had  a very  large file you wanted to transmit over a
  3720.             modem.   If the  line dropped suddenly, you wouldn't want
  3721.             to have  to start all over on a 2M file.  If you split it
  3722.             first into  200K chunks,  you'd stand to lose a lot less.
  3723.             Another example might be if you had a truly enormous text
  3724.             file that  was just  too big  to easily  edit  with  your
  3725.             favorite editor.  Splitting it up into chunks of only 10K
  3726.             lines each might be a solution.
  3727.  
  3728.  
  3729.  
  3730.             tabs
  3731.  
  3732.                tabs lets  you expand or unexpand tab characters based
  3733.             on a  set of  tab settings you give it.  Tab settings are
  3734.             religious.   I like  them every 3 spaces but you probably
  3735.             like something else.  If you're composing something to be
  3736.             sent as  email  or  posted  on  a  bulletin  board,  it's
  3737.             probably nice  to expand  it out  before you  send it  so
  3738.             everyone sees what you see.
  3739.  
  3740.  
  3741.  
  3742.             tr
  3743.  
  3744.                tr  is   a  another   simple  filter  for  translating
  3745.             characters from  input to output.  For example, you could
  3746.             translate everything from lower to upper case by typing:
  3747.  
  3748.                  59 D% tr a-z A-Z
  3749.                  hello world
  3750.                  HELLO WORLD
  3751.                  ^Z
  3752.  
  3753.             We typed  the first hello world and tr has just echoed it
  3754.             in upper  case.   ^Z is the end-of-file character defined
  3755.             by OS/2 and NT.
  3756.  
  3757.                tr also  has a  number of  options for  squeezing  out
  3758.             repeated sequences  of the  same character or editing out
  3759.             just certain characters and even for normalizing the text
  3760.             in a  file, ensuring that every line ends with a carriage
  3761.             return/line feed  combination.   That's handy  if  you're
  3762.             importing a file from another operating system.
  3763.  
  3764.  
  3765.  
  3766.  
  3767.  
  3768.                                      Page 54
  3769.  
  3770.                                                                     Utilities
  3771.  
  3772.  
  3773.              strings
  3774.  
  3775.                strings lets you simply list out all the ASCII strings
  3776.             in an  otherwise binary  file.   Sometimes  this  can  be
  3777.             useful for  spelunking around  through a file when you're
  3778.             really not  sure at  all just  what's inside it.  Various
  3779.             options are  available to  trimming the  output  so  only
  3780.             strings of  a minimum  length, etc.,  will be shown.  For
  3781.             example,
  3782.  
  3783.                  60 D% strings hello.exe
  3784.                  !This program cannot be run in DOS mode.
  3785.                  :
  3786.                  Hello, world
  3787.                  :
  3788.  
  3789.                Another  example   might  be   if  you   suspected  an
  3790.             application was  carrying a  virus.   Naturally,  strings
  3791.             can't guarantee something's free of any virus, but on the
  3792.             other  hand,  if  you  scan  it  with  strings  and  find
  3793.             something like this, obviously you should be careful:
  3794.  
  3795.                  61 D% strings a:suspect.exe
  3796.                  :
  3797.                  Aha!  Gotcha!  I just blew away your hard disk!
  3798.  
  3799.  
  3800.  
  3801.             dskread and dskwrite
  3802.  
  3803.                This pair  of utilities  can be  used to quickly copy,
  3804.             format or  mass duplicate  diskettes in  a  single  pass.
  3805.             Here's an  example using dskread to read a whole diskette
  3806.             image onto your hard disk and then write it back out onto
  3807.             a new floppy with dskwrite.  The dskwrite -a option means
  3808.             autoformat,  i.e.,   if  the   new  disk   isn't  already
  3809.             formatted, format  each track  as it's  written.   The -v
  3810.             option means read back and verify each write to be sure a
  3811.             good copy was made.
  3812.  
  3813.                  62 D% dskread a: >disk.image  # Read the whole
  3814.                  diskette
  3815.                  63 D% dskwrite -av a: <disk.image  # Make a new copy
  3816.  
  3817.                To make  more copies,  you  simply  keep  putting  new
  3818.             diskettes in  and rerunning  the  dskwrite.    Since  the
  3819.             entire diskette  image,  including  the  boot  sector  is
  3820.             captured onto  the hard disk by dskread, it's possible to
  3821.             email a  bootable diskette  image,  even  compressing  it
  3822.             first with  one of the popular compression utilities such
  3823.             as arc or pkzip.
  3824.  
  3825.                dskread and  dskwrite can  also be used to copy a very
  3826.             large file  onto a  whole series of diskettes and restore
  3827.  
  3828.  
  3829.  
  3830.                                      Page 55
  3831.  
  3832.      Utilities
  3833.  
  3834.  
  3835.             it later  as a  single file.   E.g., to back up your hard
  3836.             disk, you  might compress  whole directories using one of
  3837.             the popular compression utilities and write the resulting
  3838.             archive file  out as  1.2MB (or,  as appropriate,  1.4MB)
  3839.             chunks onto  separate diskettes.   To  restore the  file,
  3840.             just cat  or dskread  the pieces together again.  (But if
  3841.             you do  try this, be sure the compression utility you use
  3842.             can handle  any long  filenames or system or hidden files
  3843.             you have lurking in your directories.)
  3844.  
  3845.                Here's an example of writing a very large .zip file to
  3846.             a series  of diskettes.   The  -c option  means it should
  3847.             continue with  as many  diskettes as it takes to hold all
  3848.             the data,  prompting you  for each  new diskette  when it
  3849.             needs it.  The -d option causes it to write  a dummy file
  3850.             system around  the data (so it still looks like a regular
  3851.             OS/2 or  NT diskette).   The  -n option takes an argument
  3852.             specifying the  name given  the file being created on the
  3853.             diskette.   In this example, the first diskette will have
  3854.             a  file   named  ``big.001'',   the  second   will   have
  3855.             ``big.002'', etc.   Once  again,  the  -av  options  mean
  3856.             autoformat and verify each write.
  3857.  
  3858.                  64 D% dskwrite -avcd -n big a: < g:big.zip
  3859.  
  3860.                To get  it all  back, you  could simply  copy all  the
  3861.             pieces individually onto your hard disk and then cat them
  3862.             together or use dskread to do it for you:
  3863.  
  3864.                  65 D% dskread -dc -n big a: > g:big.zip
  3865.  
  3866.  
  3867.  
  3868.             Other Utilities
  3869.  
  3870.                Other utilities provide means for sleeping for a timed
  3871.             period, counting the number of words in a file and so on.
  3872.             Part of  the appeal  of Hamilton  C shell  is  that  it's
  3873.             relatively easy  to continue  expanding  the  vocabularly
  3874.             with simple utilities that may each be only a few hundred
  3875.             lines long.
  3876.  
  3877.                This has  been a  fast introduction.  Fortunately, you
  3878.             don't have  to learn  the utilities  just from  the book.
  3879.             All have  on-line information  available  with  -h.    We
  3880.             encourage you to experiment.
  3881.  
  3882.                As this  is being  written, we're still giving thought
  3883.             to additional  utilities.   If you  have favorites  you'd
  3884.             like to  see included  or maybe  offered as new products,
  3885.             please contact us.
  3886.  
  3887.  
  3888.  
  3889.  
  3890.  
  3891.  
  3892.                                      Page 56
  3893.  
  3894.                                                               I/O Redirection
  3895.  
  3896.  
  3897.             
  3898.  
  3899.  
  3900.                            I/O Redirection and Piping
  3901.  
  3902.  
  3903.  
  3904.  
  3905.             I/O Redirection
  3906.  
  3907.                You can redirect or pipe i/o in much the way you might
  3908.             under cmd.exe.    Here's  a  simple  example  redirecting
  3909.             stdout from the word count of the famous ``Hello, world''
  3910.             program.   cat just copies from any files you tell it or,
  3911.             by default, from stdin to stdout.
  3912.  
  3913.                  66 E% cd hello
  3914.                  67 D% ls
  3915.                  hello.c      hello.exe
  3916.                  68 D% cat hello.c
  3917.                  #include <stdio.h>
  3918.                  main ()
  3919.                     {
  3920.                     printf("Hello, world.\n");
  3921.                     }
  3922.                  69 D% wc hello.c >hello.wc
  3923.                  70 D% cat <hello.wc
  3924.                          5        8       72  hello.c
  3925.  
  3926.             (wc tells  us that  hello.c has  5  lines,  containing  8
  3927.             words, totalling 72 characters.)
  3928.  
  3929.                If the file you write to with ``>'' exists, it's first
  3930.             truncated to  zero length  (discarding the old contents);
  3931.             if the  file doesn't  exist, it's  created.   With ``<'',
  3932.             it's an error if the file doesn't exist.
  3933.  
  3934.                Data can  be  appended  to  a  file  with  the  ``>>''
  3935.             operator:
  3936.  
  3937.                  71 D% echo that^'s all folks >>hello.wc
  3938.                  72 D% cat hello.wc
  3939.                          5        8       72  hello.c
  3940.                  that's all folks
  3941.                  73 D% _
  3942.  
  3943.             When you  append with ``>>'', if the file exists, data is
  3944.             written onto  the end; if it doesn't exist, it's created.
  3945.             (The single  quote character  has special  meaning to the
  3946.             shell on  the command line; the special meaning is turned
  3947.             off by the shell's escape character,``^''.)
  3948.  
  3949.  
  3950.  
  3951.  
  3952.  
  3953.  
  3954.                                      Page 57
  3955.  
  3956.      I/O Redirection
  3957.  
  3958.  
  3959.             noclobber
  3960.  
  3961.                Not everyone  is comfortable  with letting  the  shell
  3962.             glibly toss  away an existing file if you type ``>'' when
  3963.             you meant  ``>>'' or  lose it somewhere if you mistype an
  3964.             existing filename  with ``>>''.   The  noclobber variable
  3965.             lets you  tell the  shell you  want this to be caught, so
  3966.             you can decide if this was really what you meant.
  3967.  
  3968.                If you  set noclobber,  you have  to  type  ``>!''  to
  3969.             redirect to an existing file:
  3970.  
  3971.                  73 D% set noclobber = 1
  3972.                  74 D% echo trash this file > hello.c
  3973.                  csh:  Couldn't open 'hello.c' as a redirected
  3974.                  standard output.
  3975.  
  3976.             Come to think of it, let's not overwrite that file.
  3977.  
  3978.                Similarly if  you want  to append  to  something  that
  3979.             doesn't already exist:
  3980.  
  3981.                  75 D% echo appended data >> newdata
  3982.                  csh:  Couldn't open 'newdata' as a redirected
  3983.                  standard output.
  3984.                  76 D% echo appended data >>! newdata
  3985.                  77 D% cat newdata
  3986.                  appended data
  3987.                  78 D% rm newdata
  3988.  
  3989.  
  3990.  
  3991.             Protection Attributes
  3992.  
  3993.                If  a   file  has   any  of   the  special  protection
  3994.             attributes, hidden,  read-only or system, set, you cannot
  3995.             overwrite it  by redirecting  i/o to  it.   Even when you
  3996.             type ``!'',  you still can't.  Before you can redirect to
  3997.             it, you must clear all these attribute bits.
  3998.  
  3999.                  79 D% ls -l zork
  4000.                  -SHAR  Feb 23  13:16         0  zork
  4001.                  80 D% echo new zork data >! zork
  4002.                  csh:  Couldn't open 'zork' as a redirected standard
  4003.                  output.
  4004.                  81 D% chmod -R zork
  4005.                  82 D% echo new zork data >! zork
  4006.                  csh:  Couldn't open 'zork' as a redirected standard
  4007.                  output.
  4008.                  83 D% chmod -SH zork
  4009.                  84 D% ls -l zork
  4010.                  ---A-  Feb 23  13:16         0  zork
  4011.                  85 D% echo new zork data > zork
  4012.                  86 D% _
  4013.  
  4014.  
  4015.  
  4016.                                      Page 58
  4017.  
  4018.                                                               I/O Redirection
  4019.  
  4020.  
  4021.             Stdout and Stderr
  4022.  
  4023.                Redirecting both stdout and stderr together is done by
  4024.             adding an  ampersand.   For example,  using echo's ``-2''
  4025.             option to  deliberately write  to stderr  and parentheses
  4026.             for a simple grouping:
  4027.  
  4028.                  86 D% (echo -2 error; echo standard) > zork
  4029.                  error
  4030.                  87 D% cat zork
  4031.                  standard
  4032.                  88 D% (echo -2 error; echo standard) >& zork
  4033.                  89 D% cat zork
  4034.                  error
  4035.                  standard
  4036.                  90 D% _
  4037.  
  4038.                Separately redirecting  stderr and stdout to different
  4039.             files is  a little tricky:  first you redirect them both,
  4040.             then redirect  stdout  by  itself.    Here's  an  example
  4041.             running the  C compiler  with stdout  to log  and  stderr
  4042.             going to errors.
  4043.  
  4044.                  90 D% cl hello.c >& errors > log
  4045.  
  4046.             You can  type as  many i/o  redirections in  a row as you
  4047.             like.   The shell  evaluates them  one after another.  If
  4048.             you redirect  to a  new file,  then redirect to something
  4049.             else, the effect is just like touch'ing the file.
  4050.  
  4051.  
  4052.  
  4053.             Pipes
  4054.  
  4055.                Pipes are  a way  of connecting a series of activities
  4056.             together so  that the  output of  one is read as input to
  4057.             the next.  Each of the activities runs asynchronously and
  4058.             concurrently with  the others.  Data is passed completely
  4059.             in memory and is very fast.
  4060.  
  4061.                The syntax is similar to i/o redirection in its use of
  4062.             the ``&''  character.  To pipe just stdout, use  ``|'' by
  4063.             itself:
  4064.  
  4065.                  91 D% ls -L | more
  4066.  
  4067.             To pipe both stdout and stderr together, use ``|&'':
  4068.  
  4069.                  92 D% cl hello\hello.c |& more
  4070.  
  4071.                The  leftmost   part  of  the  pipeline  is  evaluated
  4072.             directly by  the shell's  current thread.  The successive
  4073.             right parts  are evaluated by child threads.  (This is so
  4074.             that piping  a command  that lists  status information on
  4075.  
  4076.  
  4077.  
  4078.                                      Page 59
  4079.  
  4080.      I/O Redirection
  4081.  
  4082.  
  4083.             the current  thread through  a filter  like more operates
  4084.             sensibly.)     Each  part  of  the  pipeline  can  be  an
  4085.             arbitrarily complex  statement, perhaps  even  run  as  a
  4086.             separate OS/2 screen group or in a separate NT window.
  4087.  
  4088.                Pipes are  much faster  and more  responsive than with
  4089.             vanilla  OS/2   or  NT  due  to  improved  buffering  and
  4090.             scheduling technology.   A  long pipeline  finishes  much
  4091.             faster.   Also, when  you type  ^C to interrupt, it comes
  4092.             back immediately without a lot of nuisance messages.
  4093.  
  4094.  
  4095.  
  4096.  
  4097.  
  4098.  
  4099.  
  4100.  
  4101.  
  4102.  
  4103.  
  4104.  
  4105.  
  4106.  
  4107.  
  4108.  
  4109.  
  4110.  
  4111.  
  4112.  
  4113.  
  4114.  
  4115.  
  4116.  
  4117.  
  4118.  
  4119.  
  4120.  
  4121.  
  4122.  
  4123.  
  4124.  
  4125.  
  4126.  
  4127.  
  4128.  
  4129.  
  4130.  
  4131.  
  4132.  
  4133.  
  4134.  
  4135.  
  4136.  
  4137.  
  4138.  
  4139.  
  4140.                                      Page 60
  4141.  
  4142.                                                               I/O Redirection
  4143.  
  4144.  
  4145.             Command Substitution
  4146.  
  4147.                A particularly novel way of piping statements together
  4148.             is to  use the output of one as command line arguments of
  4149.             another.   This is  called command  substitution and  you
  4150.             indicate  it   by  typing  backquotes,  `...`,  around  a
  4151.             command.
  4152.  
  4153.                  93 D% ls +a
  4154.                  .              hello          zork
  4155.                  ..             memos
  4156.                  94 D% echo `ls +a`
  4157.                  . hello zork .. memos
  4158.                  95 D% _
  4159.  
  4160.                When command  substitution  is  done,  all  the  extra
  4161.             ``white space''  (space characters, tabs and newlines) is
  4162.             squeezed out.  Also, any ANSI escape sequences that might
  4163.             have turned  on highlighting or color, etc., are deleted.
  4164.             You just  get the  list of  words the  backquoted command
  4165.             wrote to stdout.  In this example, the order of the files
  4166.             is a bit scrambled when the line ends are removed; the -1
  4167.             (numeric one) single column option can fix this.  (Try it
  4168.             again using ls +a1 inside the backquotes.)
  4169.  
  4170.                Command substitution is especially useful anywhere you
  4171.             need to  give a  list of  filenames  as  arguments  to  a
  4172.             command.   Here's an  example using ls to give a detailed
  4173.             listing of the two more filters, the old and the new:
  4174.  
  4175.                  95 D% whereis more
  4176.                  c:\hamilton\more.exe
  4177.                  c:\os2\more.com
  4178.                  96 D% ls -l `whereis more`
  4179.                  ---A-  Mar 20  8:00      20123  c:\hamilton\more.exe
  4180.                  ---A-  Oct 26 12:00      31658  c:\os2\more.com
  4181.  
  4182.             (Our more is ``less filling and tastes better.'')
  4183.  
  4184.                The string inside the backquotes is passed directly to
  4185.             a child  thread for  interpretation.   If there  are  any
  4186.             variable substitutions  inside  the  backquotes,  they're
  4187.             done by  the child, not the parent.  This lets you easily
  4188.             embed for loops and other programming constructs into the
  4189.             command substitution.
  4190.  
  4191.                Inside backquotes,  only the backquote character needs
  4192.             to be  escaped to avoid having it processed by the parent
  4193.             thread.
  4194.  
  4195.  
  4196.  
  4197.             Inline Data
  4198.  
  4199.  
  4200.  
  4201.  
  4202.                                      Page 61
  4203.  
  4204.      I/O Redirection
  4205.  
  4206.  
  4207.                A novel  variation on  i/o redirection is inline data,
  4208.             also called  ``here'' documents:   literal  text you want
  4209.             the shell to feed a command as stdin.  Here's an example:
  4210.  
  4211.  
  4212.  
  4213.  
  4214.  
  4215.  
  4216.  
  4217.  
  4218.  
  4219.  
  4220.  
  4221.  
  4222.  
  4223.  
  4224.  
  4225.  
  4226.  
  4227.  
  4228.  
  4229.  
  4230.  
  4231.  
  4232.  
  4233.  
  4234.  
  4235.  
  4236.  
  4237.  
  4238.  
  4239.  
  4240.  
  4241.  
  4242.  
  4243.  
  4244.  
  4245.  
  4246.  
  4247.  
  4248.  
  4249.  
  4250.  
  4251.  
  4252.  
  4253.  
  4254.  
  4255.  
  4256.  
  4257.  
  4258.  
  4259.  
  4260.  
  4261.  
  4262.  
  4263.  
  4264.                                      Page 62
  4265.  
  4266.                                                               I/O Redirection
  4267.  
  4268.  
  4269.                  97 D% cat <<eof
  4270.                  98 D? (this is the inline data)
  4271.                  99 D? eof
  4272.                  (this is the inline data)
  4273.                  100 D% _
  4274.  
  4275.             The ``<<''  operator is followed by a string the shell is
  4276.             asked to  look for  to mark  the end  of the inline data.
  4277.             The end-of-data  string can  be  virtually  anything  you
  4278.             like, including  wildcard characters, dollar signs, etc.;
  4279.             their normal meaning is turned off and they're treated as
  4280.             ordinary  literal  characters.    Only  quote  or  escape
  4281.             characters have any special meaning, which is to turn off
  4282.             substitutions in  the inline  text (as we'll discuss in a
  4283.             moment).   Continuation lines  as the  shell collects the
  4284.             inline data  get a  different prompt,  controlled by  the
  4285.             prompt2 variable.   Once  the data  has been collected in
  4286.             memory, it's written through a pipe to the command.
  4287.  
  4288.                One very  convenient use  of inline  data is  when you
  4289.             want to  quickly search  for  any  one  of  a  number  of
  4290.             important words  in a  large library.   E.g., to scan for
  4291.             some specific strings in a set of C files:
  4292.  
  4293.                  100 D% fgrep -ns <<xxx ~\sh\*.c
  4294.                  101 D? DosOpen
  4295.                  102 D? DosClose
  4296.                  103 D? DosRead
  4297.                  104 D? DosWrite
  4298.                  105 D? xxx
  4299.                  :  search results
  4300.  
  4301.                In situations  where the  inline data is being created
  4302.             inside a  larger structure,  the data is assumed to start
  4303.             on the  first line  following a break between statements.
  4304.             For example, inside a for loop:
  4305.  
  4306.                  106 D% for i = 1 to 3 do
  4307.                  107 D? cat <<eof; echo i = $i
  4308.                  108 D? (this is the inline data)
  4309.                  109 D? eof
  4310.                  110 D? end
  4311.                  (this is the inline data)
  4312.                  i = 1
  4313.                  (this is the inline data)
  4314.                  i = 2
  4315.                  (this is the inline data)
  4316.                  i = 3
  4317.  
  4318.                If you  want to put several inline i/o redirections on
  4319.             the same  line, type the associated inline data sections,
  4320.             each with  its own  terminating string, in the same left-
  4321.             to-right order in which they appeared.
  4322.  
  4323.  
  4324.  
  4325.  
  4326.                                      Page 63
  4327.  
  4328.      I/O Redirection
  4329.  
  4330.  
  4331.                So far,  we've just  shown examples  involving  static
  4332.             text.   But it's  also possible  to ask  the shell  to do
  4333.             command and variable substitutions on the inline text:
  4334.  
  4335.                  111 D% cat << ***
  4336.                  112 D? The ^$home directory is $home.
  4337.                  113 D? Today's date is `date`.
  4338.                  114 D? ***
  4339.                  The $home directory is d:\doug
  4340.                  Today's date is Wed   Mar 17 1993   14:40:51.12.
  4341.                  115 D% _
  4342.  
  4343.                Notice  that   although   substitutions   and   escape
  4344.             characters inside the here document are processed, quotes
  4345.             (both single and double) are not.
  4346.  
  4347.                [The C  shell implements  here documents by spawning a
  4348.             child thread  to  do  any  substitutions  and  write  the
  4349.             results into  a pipe  feeding the  current thread  as  it
  4350.             continues  to  evaluate  the  statement.    If  the  here
  4351.             document contains references to shared variables, they'll
  4352.             be evaluated  by that  other thread.   And unless they're
  4353.             local variables,  the values will not be snapshotted when
  4354.             the here  document thread  is created.   If  the  current
  4355.             thread (or any other thread) continues to make changes to
  4356.             a variable  after the here document thread is spawned but
  4357.             before it  evaluates the variable, the here document will
  4358.             contain the new, not the old value.]
  4359.  
  4360.                Command   and   variable   substitution   and   escape
  4361.             processing inside  a here  document is  turned off if any
  4362.             part of the end-of-data string following the << is quoted
  4363.             (with single, double or backquotes) or escaped:
  4364.  
  4365.                  115 D% cat <<^***
  4366.                  116 D? The ^$home directory is $home.
  4367.                  117 D? Today's date is `date`.
  4368.                  118 D? ***
  4369.                  The ^$home directory is $home
  4370.                  Today's date is `date`.
  4371.                  119 D% _
  4372.  
  4373.  
  4374.  
  4375.             Inline Data in Scripts
  4376.  
  4377.                Inline data can be especially useful if you're writing
  4378.             a script  file or passing commands to the shell through a
  4379.             pipe.   In either  of these cases, the low-level DosReads
  4380.             to the  OS/2 kernel  (or WriteFiles  to  the  NT  kernel)
  4381.             cannot be  depended on  to stop  at the  end  of  a  line
  4382.             because pipes  and files  are  considered  block-oriented
  4383.             rather than line-oriented like the keyboard.  If too many
  4384.             characters are  read, there's  no simple  way to back up.
  4385.  
  4386.  
  4387.  
  4388.                                      Page 64
  4389.  
  4390.                                                               I/O Redirection
  4391.  
  4392.  
  4393.             For this  reason, it's  not realistic  to write  a script
  4394.             where a  child  process  is  supposed  to  inherit  stdin
  4395.             pointed into  the script file.  In a script file, this is
  4396.             not reliable:
  4397.  
  4398.  
  4399.  
  4400.  
  4401.  
  4402.  
  4403.  
  4404.  
  4405.  
  4406.  
  4407.  
  4408.  
  4409.  
  4410.  
  4411.  
  4412.  
  4413.  
  4414.  
  4415.  
  4416.  
  4417.  
  4418.  
  4419.  
  4420.  
  4421.  
  4422.  
  4423.  
  4424.  
  4425.  
  4426.  
  4427.  
  4428.  
  4429.  
  4430.  
  4431.  
  4432.  
  4433.  
  4434.  
  4435.  
  4436.  
  4437.  
  4438.  
  4439.  
  4440.  
  4441.  
  4442.  
  4443.  
  4444.  
  4445.  
  4446.  
  4447.  
  4448.  
  4449.  
  4450.                                      Page 65
  4451.  
  4452.      I/O Redirection
  4453.  
  4454.  
  4455.                  :
  4456.                  :
  4457.                  csh
  4458.                  echo hello
  4459.                  exit
  4460.                  :
  4461.                  :
  4462.  
  4463.             The file  descriptor  the  child  process  inherits  will
  4464.             likely not  be pointing  at the  ``echo hello'';  when it
  4465.             exits, the  parent will  likely not  find it pointed just
  4466.             past the ``exit''.  This type of script should be written
  4467.             as:
  4468.  
  4469.                  :
  4470.                  :
  4471.                  csh <<eof
  4472.                  echo hello
  4473.                  exit
  4474.                  eof
  4475.                  :
  4476.                  :
  4477.  
  4478.  
  4479.  
  4480.  
  4481.  
  4482.  
  4483.  
  4484.  
  4485.  
  4486.  
  4487.  
  4488.  
  4489.  
  4490.  
  4491.  
  4492.  
  4493.  
  4494.  
  4495.  
  4496.  
  4497.  
  4498.  
  4499.  
  4500.  
  4501.  
  4502.  
  4503.  
  4504.  
  4505.  
  4506.  
  4507.  
  4508.  
  4509.  
  4510.  
  4511.  
  4512.                                      Page 66
  4513.  
  4514.                                                               I/O Redirection
  4515.  
  4516.  
  4517.             
  4518.  
  4519.  
  4520.  
  4521.  
  4522.  
  4523.  
  4524.  
  4525.  
  4526.  
  4527.  
  4528.  
  4529.  
  4530.  
  4531.  
  4532.  
  4533.  
  4534.  
  4535.  
  4536.  
  4537.  
  4538.  
  4539.  
  4540.  
  4541.  
  4542.  
  4543.  
  4544.  
  4545.  
  4546.  
  4547.  
  4548.  
  4549.  
  4550.  
  4551.  
  4552.  
  4553.  
  4554.  
  4555.  
  4556.  
  4557.  
  4558.  
  4559.  
  4560.  
  4561.  
  4562.  
  4563.  
  4564.  
  4565.  
  4566.  
  4567.  
  4568.  
  4569.  
  4570.  
  4571.  
  4572.  
  4573.  
  4574.                                      Page 67
  4575.  
  4576.      History
  4577.  
  4578.  
  4579.             
  4580.  
  4581.  
  4582.                               The History Mechanism
  4583.  
  4584.  
  4585.  
  4586.  
  4587.             History
  4588.  
  4589.                The  history  mechanism  lets  you  recall  and  rerun
  4590.             earlier commands.   To see what it's remembered,  use the
  4591.             history command  or its  usual alias  h, which might show
  4592.             you something like the following:
  4593.  
  4594.                  119 D% history 12
  4595.                     108  (this is the inline data)
  4596.                     109  eof
  4597.                     110  end
  4598.                     111  cat << ***
  4599.                     112  The ^$home directory is $home.
  4600.                     113  Today's date is `date`.
  4601.                     114  ***
  4602.                     115  cat << ^***
  4603.                     116  The ^$home directory is $home.
  4604.                     117  Today's date is `date`.
  4605.                     118  ***
  4606.                     119  history 12
  4607.                  120 D% _
  4608.  
  4609.                The history  list won't be quite what you typed: it'll
  4610.             be broken  into separate  words  wherever    one  of  the
  4611.             special tokens,  &, |,  ;, >,  <, (, ), &&, ||, >> or <<,
  4612.             occurs.   Only inline  data escapes  being broken up into
  4613.             words this  way.   Each command  may be  thought of as an
  4614.             array of words, indexed from 0.+
  4615.  
  4616.                To reuse  the text  or maybe  just a  few words from a
  4617.             previous command,  you type  an exclamation point, ``!'',
  4618.             followed by a few characters to identify what you want to
  4619.             reuse.   You can do this anywhere and whatever you select
  4620.             is  just   stuffed  back   on  the  command  line  to  be
  4621.             interpreted  as  whatever  the  context  suggests.    For
  4622.             convenience, the  exclamation point  is not  treated as a
  4623.             history reference  if it's  followed by  white  space  (a
  4624.             space, tab or newline) or by ``='', ``~'' or ``(''.
  4625.  
  4626.  
  4627.  
  4628.             Retrieving a Whole Command Line
  4629.  
  4630.  
  4631.             ____________________
  4632.             + Array indices always start with zero.
  4633.  
  4634.  
  4635.  
  4636.                                      Page 68
  4637.  
  4638.                                                                       History
  4639.  
  4640.  
  4641.                There several ways of picking up a whole command line.
  4642.             You already  know how  to do  it interactively with arrow
  4643.             keys  and  command  completion.    You  can  also  use  a
  4644.             shorthand notation  that can  be more  convenient if  you
  4645.             want to  do something  a bit  more complex.  The simplest
  4646.             shorthand is  ``!!'', which  picks up  the  text  of  the
  4647.             immediately preceding command:
  4648.  
  4649.                  120 D% echo !!
  4650.                  echo history 12
  4651.                  history 12
  4652.                  121 D% !!
  4653.                  echo history 12
  4654.                  history 12
  4655.                  122 D% _
  4656.  
  4657.             The shell  first echoes  your command showing the effects
  4658.             of the  substitutions and  then runs it.  The other quick
  4659.             ways of  referring to  a whole  command line from history
  4660.             are by the command number,
  4661.  
  4662.                  122 D% !96
  4663.                  ls -l  whereis more`
  4664.                  ---A-  Nov 28  16:57   24743  c:\os2\bin\more.exe
  4665.                  ---A-  Oct 21   1987   48354  c:\os2\cmds\more.com
  4666.  
  4667.             relative to the immediately preceding command+,
  4668.  
  4669.                  123 D% echo one
  4670.                  one
  4671.                  124 D% echo two
  4672.                  two
  4673.                  125 D% echo three
  4674.                  three
  4675.                  126 D% !-1
  4676.                  echo two
  4677.                  two
  4678.                  127 D% _
  4679.  
  4680.             or by  mentioning some  of the  text  to  look  for.    A
  4681.             question mark  after the  exclamation point  means you'll
  4682.             accept the  match anywhere  on the line; otherwise it has
  4683.             to be at the start.
  4684.  
  4685.                  128 D% !h
  4686.                  history 12
  4687.                     116  The ^$home directory is $home.
  4688.             ____________________
  4689.             + In this  context, the history list can be thought of as
  4690.               an array  starting with  the zeroth  element being  the
  4691.               immediately preceding command line.  The negative index
  4692.               captures the  notion of  counting backwards in time and
  4693.               differentiates the  syntax from  references by  command
  4694.               number.  See also the bsdhistory variable.
  4695.  
  4696.  
  4697.  
  4698.                                      Page 69
  4699.  
  4700.      History
  4701.  
  4702.  
  4703.                     117  Today's date is `date`.
  4704.                     118  ***
  4705.                     119  history 12
  4706.                     120  echo history 12
  4707.                     121  echo history 12
  4708.                     122  ls -l  `whereis more`
  4709.                     123  echo one
  4710.                     124  echo two
  4711.                     125  echo three
  4712.                     126  echo two
  4713.                     127  history 12
  4714.  
  4715.             A search string ends at the first word boundary.  This is
  4716.             so it's  convenient to  type  additional  text  following
  4717.             without having  it be  confused as  part  of  the  search
  4718.             string.  For example:
  4719.  
  4720.                  128 D% !?one;!?two;!?thr
  4721.                  echo one ; echo two ; echo three
  4722.                  one
  4723.                  two
  4724.                  three
  4725.                  129 D% _
  4726.  
  4727.  
  4728.  
  4729.             Retrieving Individual Words
  4730.  
  4731.                To  pick  off  individual  words  of  the  immediately
  4732.             preceding command,  there's  some  convenient  shorthand.
  4733.             ``!*'' gets all the argument words:
  4734.  
  4735.                  129 D% echo now is the time
  4736.                  now is the time
  4737.                  130 D% echo Finally, !* to begin
  4738.                  echo Finally, now is the time to begin
  4739.                  Finally, now is the time to begin
  4740.                  131 D% _
  4741.  
  4742.             ``!$'' gets just the last word:
  4743.  
  4744.                  131 D% echo the last word was !$.
  4745.                  echo the last word was begin.
  4746.                  the last word was begin.
  4747.                  132 D% _
  4748.  
  4749.             and ``!^'' gets just the first argument word:
  4750.  
  4751.                  132 D% echo ===!^=== time is here
  4752.                  echo ===the=== time is here
  4753.                  ===the=== time is here
  4754.                  133 D% _
  4755.  
  4756.  
  4757.  
  4758.  
  4759.  
  4760.                                      Page 70
  4761.  
  4762.                                                                       History
  4763.  
  4764.  
  4765.             Notice that  a history  substitution can be smashed right
  4766.             up against other literal text.
  4767.  
  4768.                In the  chapter on  editing, additional facilities for
  4769.             selecting individual words or doing a search/replace will
  4770.             be introduced.
  4771.  
  4772.  
  4773.  
  4774.             History Short-Form
  4775.  
  4776.                Recognizing how  frequently one  would like  to make a
  4777.             simple change  to the  immediately preceding  command  to
  4778.             correct a  typo, the  history mechanism  provides a short
  4779.             form for  just that  purpose.   ``%'' typed  as the first
  4780.             character  on   the  command   line  indicates   that   a
  4781.             search/replace pair follows:
  4782.  
  4783.                  133 D% echo hello world
  4784.                  hello world
  4785.                  134 D% %world%friends%
  4786.                  echo hello friends
  4787.                  hello friends
  4788.  
  4789.                Typing ``%%'' matches the beginning of the line:
  4790.  
  4791.                  135 D% %%echo %
  4792.                  echo echo hello friends
  4793.                  echo hello friends
  4794.  
  4795.                It's also  possible to  refer to  the search string in
  4796.             the replacement  string by  using an  ampersand.    (This
  4797.             example also  illustrates that  the trailing  ``%'' isn't
  4798.             required unless  you want  to explicitly  mark the end of
  4799.             the replacement.)
  4800.  
  4801.                  136 D% %friends%family, & and neighbors
  4802.                  echo echo hello family, friends and neighbors
  4803.                  echo hello family, friends and neighbors
  4804.                  137 D% _
  4805.  
  4806.                Obviously, that raises the question:  how do you put a
  4807.             literal ampersand  in the  replacement?   Simple.    Just
  4808.             quote it with ``^'', the shell escape character.
  4809.  
  4810.                  137 D% %and%^&
  4811.                  echo hello family, friends & neighbors
  4812.                  hello family, friends & neighbors
  4813.                  138 D% _
  4814.  
  4815.  
  4816.  
  4817.  
  4818.  
  4819.  
  4820.  
  4821.  
  4822.                                      Page 71
  4823.  
  4824.      Variables
  4825.  
  4826.  
  4827.             
  4828.  
  4829.  
  4830.                                     Variables
  4831.  
  4832.  
  4833.                As with  any conventional  programming  language,  the
  4834.             shell  provides   a  facility   for  storing   values  in
  4835.             variables.
  4836.  
  4837.  
  4838.  
  4839.             Environmental Variables
  4840.  
  4841.                Some of  the variables  are part  of the  environment,
  4842.             passed along  to any child process or screen group.  Many
  4843.             of the  environment variables will have been created just
  4844.             this way,  e.g., set  to a  value passed  along when  you
  4845.             start the  C shell  from Group  Main  (on  OS/2)  or  the
  4846.             Program  Manager  (on  NT).    To  list  those  currently
  4847.             defined, use  the  setenv  command.    (If  you're  using
  4848.             Windows NT, mentally edit this example to imagine it says
  4849.             nt everywhere you see os2.)
  4850.  
  4851.                  138 D% setenv
  4852.                  COMSPEC      c:\os2\cmd.exe
  4853.                  COLORS       white on blue
  4854.                  DPATH
  4855.                  c:\os2;c:\os2\system;c:\os2\install;c:\;
  4856.                  HOME         d:\doug
  4857.                  INCLUDE      c:\os2\include
  4858.                  LIB          c:\os2\lib
  4859.                  PATH         .;c:\os2\bin;c:\os2\cmds;c:\os2
  4860.                  PROMPT       $iOS/2 $n$g
  4861.                  PROMPT1      $@ $CDISK%
  4862.                  PROMPT2      $@ $CDISK?
  4863.                  SHELL        c:\os2\bin\csh.exe
  4864.                  TABS         3
  4865.                  TMP          e:\tmp
  4866.  
  4867.                Variable names  are case-sensitive  on OS/2  but case-
  4868.             insensitive on  NT.   They can be of arbitrary length.  A
  4869.             name must  start with  an upper- or lower-case alphabetic
  4870.             character  or  underscore  (``_'')  or  at-sign  (``@'');
  4871.             remaining characters  may any of these or decimal digits.
  4872.             Many  of   the  environmental   variables  have  specific
  4873.             meanings.   For example, the PATH variable tells where to
  4874.             look for  executable files,  etc.  Details describing the
  4875.             meaning of  each  variable  are  given  in  the  language
  4876.             reference section.
  4877.  
  4878.                The setenv  command can  also be  used to create a new
  4879.             environmental variable  or alter  or display the value of
  4880.             an existing one:
  4881.  
  4882.  
  4883.  
  4884.                                      Page 72
  4885.  
  4886.                                                                     Variables
  4887.  
  4888.  
  4889.                  139 D% setenv zork = this is the zork variable
  4890.                  140 D% setenv zork
  4891.                  zork         this is the zork variable
  4892.                  141 D% _
  4893.  
  4894.                If the  list of  words being  assigned to the variable
  4895.             includes any special tokens, it's often useful to use the
  4896.             parenthesized variant  of setenv.   In  this example, the
  4897.             ``>'' would  have been  confused as an i/o redirection if
  4898.             it  weren't   inside  parenthesis.     Notice   that  the
  4899.             parenthesis are  stripped off  before the  assignment  is
  4900.             made.
  4901.  
  4902.                  141 D% setenv greatest = (At Berkeley, they say 4.3
  4903.                  > V)
  4904.                  142 D% setenv greatest
  4905.                  greatest     At Berkeley, they say 4.3 > V
  4906.  
  4907.                Even though  the special  meaning is lost, text inside
  4908.             the parenthesis is still broken down into words, as shown
  4909.             in this example:
  4910.  
  4911.                  143 D% setenv pdirs =
  4912.                  (.;c:\os2\bin;c:\os2\cmds;c:\os2;)
  4913.                  144 D% setenv pdirs
  4914.                  pdirs        . ; c:\os2\bin ; c:\os2\cmds ; c:\os2
  4915.  
  4916.                (To avoid  having the  text broken  up into words, use
  4917.             single or double quotes around the string instead.)
  4918.  
  4919.  
  4920.  
  4921.             Set Variables
  4922.  
  4923.                Set variables do not get passed to a child process but
  4924.             are shared  among all  threads.   To get  a list of those
  4925.             currently defined, use the set command:
  4926.  
  4927.                  145 D% set
  4928.                  CDISK        D
  4929.                  argv
  4930.                  cdhome       0
  4931.                  cdisk        d
  4932.                  :
  4933.                  :
  4934.                  path         . c:\os2\bin c:\os2\cmds c:\os2
  4935.                  precision    6
  4936.                  :
  4937.                  :
  4938.  
  4939.                Some  of   the  set   variables  are   linked  to  the
  4940.             environmental variables:  you change  one, and  the other
  4941.             changes  too.    For  example,  path  contains  the  same
  4942.  
  4943.  
  4944.  
  4945.  
  4946.                                      Page 73
  4947.  
  4948.      Variables
  4949.  
  4950.  
  4951.             information as  PATH but,  because it's  been parsed into
  4952.             individual words, it's often a bit more useful.
  4953.  
  4954.                On NT,  this linkage  can pose  a bit  of  a  problem.
  4955.             Since  the   convention  on   NT  is  that  environmental
  4956.             variables are  supposed  to  be  case-insensitive,  there
  4957.             clearly is  a conflict  between, for  example,  the  PATH
  4958.             environmental and  path  set  variables.    The  C  shell
  4959.             resolves this  by making  the set, unset and @ statements
  4960.             case-sensitive (so  you can  still create  set  variables
  4961.             that differ  from environmental  variables only  by case)
  4962.             but the  setenv and  unsetenv and $var and other variable
  4963.             references   first    try   case-sensitive,   then   case
  4964.             insensitive variable lookups.
  4965.  
  4966.                Many of the set variables are pre-defined by the shell
  4967.             to control  various aspects  of how  errors are  handled,
  4968.             etc.   In some cases, each thread maintains its own copy.
  4969.             For example,  it wouldn't  do to  insist that all threads
  4970.             must use  the same  value for  the cwd  (current  working
  4971.             directory)  variable!     The   rest  of  the  variables,
  4972.             including any  defined by  the user, are shared among all
  4973.             threads:   if one  thread changes  a value, all the other
  4974.             threads see  the change immediately.  As we'll see later,
  4975.             this  has  some  implications  when  spawning  background
  4976.             activities.
  4977.  
  4978.                In other respects, set works just like setenv:
  4979.  
  4980.                  146 D% set privatezork = this is the private zork
  4981.                  variable
  4982.                  147 D% set privatezork
  4983.                  privatezork   this is the private zork variable
  4984.                  148 D% _
  4985.  
  4986.                Once a variable has been created as either a set or an
  4987.             environmental variable,  it stays that way:  to change it
  4988.             from  set   to  environmental,   you  must   first  unset
  4989.             (unsetenv) it, then redefine it.
  4990.  
  4991.  
  4992.  
  4993.             Local Variables
  4994.  
  4995.                We just  mentioned that  not all  the pre-defined  set
  4996.             variables are  shared.   Individual threads get their own
  4997.             private copies  of some  because to do otherwise wouldn't
  4998.             be sensible.  Sometimes you need the same sort of control
  4999.             over the variables you create.  You don't want to share a
  5000.             variable with other threads or even with commands outside
  5001.             a very narrow context.
  5002.  
  5003.                You accomplish  this making  the variable local, which
  5004.             means it's  hidden from  outer control  blocks  or  other
  5005.  
  5006.  
  5007.  
  5008.                                      Page 74
  5009.  
  5010.                                                                     Variables
  5011.  
  5012.  
  5013.             threads.   Local variables are really important, as we'll
  5014.             see later, for recursive procedures or for procedures you
  5015.             want to  use from multiple threads.  To define a variable
  5016.             as local,  use the local statement, which accepts a list,
  5017.             separated with commas, of all the variable names you want
  5018.             to be  local.   When a new local variable is created, its
  5019.             initial value  is always null (zero words), even if there
  5020.             was a  previous definition.   Here  you can  see how  the
  5021.             variable i  is redefined inside the nested statements but
  5022.             once you  exit from the nest, the old value of i is again
  5023.             visible:
  5024.  
  5025.                  148 D% set i = hello world
  5026.                  149 D% echo $i
  5027.                  hello world
  5028.                  150 D% (local i; echo $i; set i = how are you; echo
  5029.                  $i)
  5030.                  
  5031.                  how are you
  5032.                  151 D% echo $i
  5033.                  hello world
  5034.  
  5035.                When you  spawn a  child thread, e.g., as a background
  5036.             activity or  as  the  second  or  following  stage  of  a
  5037.             pipeline, it  gets copies  of all  your local  variables,
  5038.             snapshotted at  the time  it's spawned.   If  either  the
  5039.             parent or  the child  later changes  to the  value of any
  5040.             those local variables, they affect only its own copy.
  5041.  
  5042.  
  5043.  
  5044.  
  5045.  
  5046.  
  5047.  
  5048.  
  5049.  
  5050.  
  5051.  
  5052.  
  5053.  
  5054.  
  5055.  
  5056.  
  5057.  
  5058.  
  5059.  
  5060.  
  5061.  
  5062.  
  5063.  
  5064.  
  5065.  
  5066.  
  5067.  
  5068.  
  5069.  
  5070.                                      Page 75
  5071.  
  5072.      Variables
  5073.  
  5074.  
  5075.             Variable Substitutions
  5076.  
  5077.                The simplest  way to  use a  variable is  in a  simple
  5078.             substitution, where  a dollar  sign is  used to  indicate
  5079.             that a variable name follows.   (Similar to using a ``%''
  5080.             in cmd.exe.)    The  value  is  substituted  in  and  the
  5081.             statement is evaluated.
  5082.  
  5083.                  152 D% echo $HOME
  5084.                  d:\doug
  5085.  
  5086.                Text surrounding  the variable  reference is generally
  5087.             just pasted around the value that's substituted in:
  5088.  
  5089.                  153 D% echo My home directory is ---$HOME---
  5090.                  My home directory is ---d:\doug---
  5091.  
  5092.                If the  surrounding text  would be confused as part of
  5093.             the  variable   name,  it's  necessary  to  insulate  the
  5094.             variable reference with braces.  For example:
  5095.  
  5096.                  154 D% echo ${HOME}XXX
  5097.                  d:\dougXXX
  5098.  
  5099.  
  5100.  
  5101.             nonovar
  5102.  
  5103.                If you  try to  reference a  variable, procedure or an
  5104.             alias and  it doesn't  exist, it's  considered  an  error
  5105.             unless you  set the  nonovar variable to indicate how you
  5106.             want the situation treated.
  5107.  
  5108.                  155 D% echo $nonesuch
  5109.                  csh:  The variable 'nonesuch' is not defined.  To
  5110.                  suppress this error, set nonovar = 1 (pass through)
  5111.                  or 2 (discard).
  5112.                  156 D% set nonovar = 1
  5113.                  157 D% !e
  5114.                  echo $nonesuch
  5115.                  $nonesuch
  5116.                  158 D% set nonovar = 2
  5117.                  159 D% !e
  5118.                  echo $nonesuch
  5119.                  
  5120.                  160 D% set nonovar = 0
  5121.  
  5122.  
  5123.  
  5124.             How Variables are Stored
  5125.  
  5126.                Each variable  is kept internally as a list (an array)
  5127.             of objects.   An  individual object  can be  a  (possibly
  5128.             null) character  string, a  32-bit integer  or  a  64-bit
  5129.  
  5130.  
  5131.  
  5132.                                      Page 76
  5133.  
  5134.                                                                     Variables
  5135.  
  5136.  
  5137.             floating point  value.    Generally  speaking,  it's  not
  5138.             necessary to  worry too  much about how a specific object
  5139.             is represented,  though, since  the  shell  automatically
  5140.             does any  necessary conversions  to allow  a value  to be
  5141.             used sensibly in any given context.
  5142.  
  5143.                Notice, however,  that even  though the  value  of  an
  5144.             environmental variable  may  be  a  list,  it  is  always
  5145.             rendered as a simple character string when it's passed to
  5146.             a child  process.   Here's an  example using  the  ``$#''
  5147.             notation to ask how many words are in a variable's value:
  5148.  
  5149.                  161 D% echo $zork
  5150.                  this is the zork variable
  5151.                  162 D% echo $#zork
  5152.                  5
  5153.                  163 D% csh
  5154.                  Hamilton C shell(tm) Release 2.2
  5155.                  Copyright (c) 1988-1993 by Hamilton Laboratories.
  5156.                  All rights reserved.
  5157.                  1 D% echo $zork
  5158.                  this is the zork variable
  5159.                  2 D% echo $#zork
  5160.                  1
  5161.                  3 D% exit
  5162.                  164 D% _
  5163.  
  5164.             In this example, zork holds five words: ``this,'' ``is,''
  5165.             ``the,'' ``zork,''  and ``variable.''   But when we start
  5166.             up a  new child  process running  the  shell,  the  child
  5167.             process sees  zork as holding only a single word:  ``this
  5168.             is the zork variable''.
  5169.  
  5170.                Here's another  example where  we  assign  a  floating
  5171.             point value to an environmental variable.  In the current
  5172.             process, the  exact  binary  floating  representation  is
  5173.             used.   When it's passed to a child process, the value is
  5174.             first converted to a character string, losing some of the
  5175.             precision.     This  example  also  introduces  the  calc
  5176.             statement which  evaluates an  expression and  prints the
  5177.             value.   In an  expression, a variable name is recognized
  5178.             even without a ``$'' to introduce it; in fact, that's the
  5179.             preferable way  to do  it.   If  you  use  a  ``$''-style
  5180.             variable substitution,  the shell  pastes in a character-
  5181.             string representation, again losing precision.  Also, the
  5182.             full  range   of  C   language  expression  operators  is
  5183.             available.
  5184.  
  5185.                  164 D% setenv envVar = 0
  5186.                  165 D% calc ++envVar
  5187.                  1
  5188.                  166 D% calc envVar /= 7
  5189.                  0.142857
  5190.                  167 D% calc envVar*7
  5191.  
  5192.  
  5193.  
  5194.                                      Page 77
  5195.  
  5196.      Variables
  5197.  
  5198.  
  5199.                  1.000000
  5200.                  168 D% csh <<eof
  5201.                  169 D? calc envVar*7
  5202.                  170 D? exit
  5203.                  171 D? eof
  5204.                  Hamilton C shell(tm) Release 2.2
  5205.                  Copyright (c) 1988-1993 by Hamilton Laboratories.
  5206.                  All rights reserved.
  5207.                  0.999999
  5208.                  172 D% calc $envVar*7
  5209.                  0.999999
  5210.  
  5211.  
  5212.  
  5213.             Arrays
  5214.  
  5215.                Variables can  hold a  list of  values indexed  as  an
  5216.             array.   As with  the C  language,  arrays  are  indexed,
  5217.             counting from  zero, with  an expression inside ``[...]''
  5218.             brackets.  The expression can be arbitrarily complex, but
  5219.             it must  evaluate to  an exact  integer value.   The next
  5220.             example shows how a floating point value can be used, but
  5221.             if it's  not precisely an integer, an error results.  The
  5222.             precision variable controls the number of digits past the
  5223.             decimal point  used  when  displaying  a  floating  point
  5224.             value; the maximum is 17 digits.
  5225.  
  5226.                  173 D% set x = now is the time for all good men
  5227.                  174 D% calc x[5.000000]
  5228.                  all
  5229.                  175 D% calc 2**500
  5230.                  3.27339061e+150
  5231.                  176 D% calc y = log2(!$)/100
  5232.                  calc y = log2 ( 2**500 ) /100
  5233.                  5.000000
  5234.                  177 D% calc x[y]
  5235.                  csh:  Couldn't evaluate the index to the variable
  5236.                  'x'.
  5237.                  178 D% set precision = 30
  5238.                  179 D% calc precision
  5239.                  17
  5240.                  180 D% calc y
  5241.                  5.00000000000000100
  5242.                  181 D% calc x[round(y)]
  5243.                  all
  5244.  
  5245.                An array  cannot be  ``sparse;'' i.e.,  before you can
  5246.             create an element 5, element 4 must exist and so on.  But
  5247.             it's perfectly legal to keep adding new elements onto the
  5248.             end of  array as  long as  the new  element is the zeroth
  5249.             element or  only one  past whatever's  currently the last
  5250.             element.   Here's an  example using  a for  loop.   The @
  5251.             statement is like calc except it doesn't print anything.
  5252.  
  5253.  
  5254.  
  5255.  
  5256.                                      Page 78
  5257.  
  5258.                                                                     Variables
  5259.  
  5260.  
  5261.                  182 D% unset x
  5262.                  183 D% for i = 0 to 4 do
  5263.                  184 D? @ x[i] = 2*i
  5264.                  185 D? end
  5265.                  186 D% echo $x
  5266.                  0 2 4 6 8
  5267.  
  5268.  
  5269.  
  5270.             nullwords
  5271.  
  5272.                When you  index an  array, if  the element you specify
  5273.             doesn't exist,  that's normally considered an error.  For
  5274.             example, x  contains 5 words; trying to reference a sixth
  5275.             fails:
  5276.  
  5277.                  187 D% calc x[5]
  5278.                  csh:  Illegal subscript in variable reference
  5279.                  'x[5]'.  (To suppress this error, set nullwords =
  5280.                  1.)
  5281.  
  5282.                The nullwords  variable is used to tell the shell that
  5283.             you'd like  to ignore subscripting errors when you try to
  5284.             evaluate a  variable reference.   nullwords has no effect
  5285.             over subscripting errors when you try to set the value of
  5286.             a non-existent element.  Here are some examples:
  5287.  
  5288.                  188 D% set nullwords = 1
  5289.                  189 D% echo -- "--->$x[999]<---"
  5290.                  ---><---
  5291.                  190 D% calc x[999] = "does not work"
  5292.                  csh:  Illegal subscript in variable reference
  5293.                  'x[999]'.
  5294.  
  5295.             The use  of the  ``--'' option  and of  double quotes was
  5296.             important:   ``--'' told echo that it had reached the end
  5297.             of any options, allowing it to print something that began
  5298.             with a  minus sign.   The  quotes were used, in the first
  5299.             case, to  turn off  recognition of redirection characters
  5300.             ``>'' and  ``<'' but still get the variable substitution.
  5301.             The second  time, it  was to  make the string, ``does not
  5302.             work'' a single word.  (If you try leaving off the quotes
  5303.             or not  using ``--,''  you'll see that the error messages
  5304.             are what you'd expect.)
  5305.  
  5306.  
  5307.  
  5308.  
  5309.  
  5310.  
  5311.  
  5312.  
  5313.  
  5314.  
  5315.  
  5316.  
  5317.  
  5318.                                      Page 79
  5319.  
  5320.      Variables
  5321.  
  5322.  
  5323.             
  5324.  
  5325.  
  5326.  
  5327.  
  5328.  
  5329.  
  5330.  
  5331.  
  5332.  
  5333.  
  5334.  
  5335.  
  5336.  
  5337.  
  5338.  
  5339.  
  5340.  
  5341.  
  5342.  
  5343.  
  5344.  
  5345.  
  5346.  
  5347.  
  5348.  
  5349.  
  5350.  
  5351.  
  5352.  
  5353.  
  5354.  
  5355.  
  5356.  
  5357.  
  5358.  
  5359.  
  5360.  
  5361.  
  5362.  
  5363.  
  5364.  
  5365.  
  5366.  
  5367.  
  5368.  
  5369.  
  5370.  
  5371.  
  5372.  
  5373.  
  5374.  
  5375.  
  5376.  
  5377.  
  5378.  
  5379.  
  5380.                                      Page 80
  5381.  
  5382.                                                                   Wildcarding
  5383.  
  5384.  
  5385.             
  5386.  
  5387.  
  5388.                                    Wildcarding
  5389.  
  5390.  
  5391.                The notion  of wildcarding is pretty simple:  the user
  5392.             gives just  a few characters describing the filename he's
  5393.             looking  for   and  system  fills  in  the  rest.    With
  5394.             ``vanilla'' OS/2 or NT, wildcarding is the responsibility
  5395.             of each  application, based on the command-line arguments
  5396.             it's given.  Typically, the application designer fulfills
  5397.             this by linking in a library routine which does a simple-
  5398.             minded half-hearted wildcarding.
  5399.  
  5400.                Hamilton C  shell does the wildcarding before invoking
  5401.             the application.   The  shell's wildcarding includes five
  5402.             components:     home  directory   expansion,  wildcarding
  5403.             characters,   ranges,    alternation    and    indefinite
  5404.             directories.   A powerful  recursive match  algorithm  is
  5405.             employed to  guarantee a  sensible result  no matter  how
  5406.             complex the pattern.
  5407.  
  5408.  
  5409.  
  5410.             Home Directory Expansion
  5411.  
  5412.                The tilde character, ``~'', is recognized as shorthand
  5413.             for the home directory.  In the simplest form, we can use
  5414.             it just by itself:
  5415.  
  5416.                  191 D? echo $home
  5417.                  d:\doug
  5418.                  192 D% cd ~
  5419.                  193 D% cd
  5420.                  d:\doug
  5421.  
  5422.                There's also shorthand for children or siblings of the
  5423.             home directory:
  5424.  
  5425.                  194 D% cd ~\samples
  5426.                  195 D% cd
  5427.                  d:\doug\samples
  5428.                  196 D% cd ~carol
  5429.                  197 D% cd
  5430.                  d:\carol
  5431.  
  5432.  
  5433.  
  5434.             Wildcard Characters
  5435.  
  5436.                The wildcard  characters,  ``*''  and  ``?'',  provide
  5437.             shorthand for ``match any string'' and ``match any single
  5438.             character,'' respectively.
  5439.  
  5440.  
  5441.  
  5442.                                      Page 81
  5443.  
  5444.      Wildcarding
  5445.  
  5446.  
  5447.                Suppose the  home directory  contained  the  following
  5448.             contents:
  5449.  
  5450.                  198 D% cd ~
  5451.                  199 D% ls
  5452.  
  5453.  
  5454.  
  5455.  
  5456.  
  5457.  
  5458.  
  5459.  
  5460.  
  5461.  
  5462.  
  5463.  
  5464.  
  5465.  
  5466.  
  5467.  
  5468.  
  5469.  
  5470.  
  5471.  
  5472.  
  5473.  
  5474.  
  5475.  
  5476.  
  5477.  
  5478.  
  5479.  
  5480.  
  5481.  
  5482.  
  5483.  
  5484.  
  5485.  
  5486.  
  5487.  
  5488.  
  5489.  
  5490.  
  5491.  
  5492.  
  5493.  
  5494.  
  5495.  
  5496.  
  5497.  
  5498.  
  5499.  
  5500.  
  5501.  
  5502.  
  5503.  
  5504.                                      Page 82
  5505.  
  5506.                                                                   Wildcarding
  5507.  
  5508.  
  5509.                  bcs         mandel      sh          ex.rc
  5510.                  release.csh
  5511.                  bix         mba         testcode    icon.ico
  5512.                  ring.ico
  5513.                  channel.one online      util        login.csh
  5514.                  snapshot.csh
  5515.                  dial        postscpt    word        mail
  5516.                  startup.csh
  5517.                  excel       regressn    backup.csh  os2init.cmd
  5518.                  vi.ini
  5519.                  games       resume      brite.csh   popup.txt
  5520.                  icon        samples     class.txt   prime.c
  5521.  
  5522.                The following  example shows the use of ``?'' to match
  5523.             any single  character.  Wildcard results are always shown
  5524.             alphabetically in  lower case.   No  distinction is  made
  5525.             between directories and files.
  5526.  
  5527.                  200 D% echo ????
  5528.                  dial icon mail util word
  5529.                  201 D% echo b??
  5530.                  bcs bix
  5531.  
  5532.                The ``*''  can match zero or more arbitrary characters
  5533.             except  ``:''   or  ``\'';   in  contrast   to  DOS-style
  5534.             wildcarding,  ``*''  can  match  ``.''.    If  there  are
  5535.             ordinary characters  in the  pattern, they  must also  be
  5536.             matched.
  5537.  
  5538.                  202 D% echo *mp*e*
  5539.                  samples
  5540.  
  5541.                Because the  wildcarding is done before the command is
  5542.             invoked  (without   the  command   even   being   aware),
  5543.             wildcarding can even be done on a cd command:
  5544.  
  5545.                  203 D% cd !$
  5546.                  cd *mp*e*
  5547.                  204 D% cd
  5548.                  d:\doug\samples
  5549.  
  5550.                Wildcarding is  most emphatically  not  restricted  to
  5551.             matches only against a single directory level.  Here's an
  5552.             example that  wildcards across  all  the  subdirectories,
  5553.             looking for .c files that begin with ``a''.
  5554.  
  5555.                  205 D% cd ..
  5556.                  206 D% echo *\a*.c
  5557.                  samples\args.c sh\allocate.c
  5558.  
  5559.                Wildcarding can  even be  done  against  driveletters.
  5560.             For example:
  5561.  
  5562.  
  5563.  
  5564.  
  5565.  
  5566.                                      Page 83
  5567.  
  5568.      Wildcarding
  5569.  
  5570.  
  5571.                  207 D% echo *:\*\q*
  5572.                  i:\mail\quotes.doc i:\tmp\query.out
  5573.                  j:\doug\quantity.disc
  5574.  
  5575.             When  wildcarding   against   driveletters,   the   shell
  5576.             restricts the  set of  drives it will search down to just
  5577.             those specified  by the  DRIVEMASK environment  variable.
  5578.             If you  don't specify  a DRIVEMASK,  the default  is  all
  5579.             drives except  the floppies  a: and  b:.   The search  is
  5580.             restricted so  you don't waste time trying to access slow
  5581.             removable media that may not even be ready.
  5582.  
  5583.  
  5584.  
  5585.             Ranges
  5586.  
  5587.                Ranges describe  a set of characters, any one of which
  5588.             will be  matched.  It's specified as a list of acceptable
  5589.             characters inside ``[...]'' brackets.  The range ``[be]''
  5590.             means either  ``b'' or  ``e''; ``[b-e]'' is shorthand for
  5591.             any  character  in  the  sequence  ``b''  through  ``e''.
  5592.             Within the  brackets, any  number of hyphenated sequences
  5593.             and single  characters can  pasted one after the other in
  5594.             any order.   For example, ``[a-cu-zgkmp]'' is a perfectly
  5595.             legal range.   Here  are a  couple examples.  Notice that
  5596.             ranges can also be used with driveletters.
  5597.  
  5598.                  208 D% echo [be]*
  5599.                  backup.csh bcs bix brite.csh ex.rc excel
  5600.                  209 D% echo[d-g]:\[s-t]*
  5601.                  d:\taxes d:\tmp e:\spool e:\startup.cmd e:\temp
  5602.                  e:\toolkit.sys f:\swap f:\tmp f:\toys g:\skip
  5603.                  g:\temp g:\tmp
  5604.  
  5605.                An exclusion  range is  written as a set of characters
  5606.             inside the brackets that starts with a circumflex.  It'll
  5607.             match any single character not in the range.
  5608.  
  5609.                  210 D% echo [^a-t]*
  5610.                  util vi.ini word
  5611.  
  5612.  
  5613.  
  5614.             Alternation
  5615.  
  5616.                Alternation, specified  with ``{...}''  braces,  is  a
  5617.             shorthand way  of specifying that all the combinations of
  5618.             frontparts and backparts should be generated. There isn't
  5619.             any requirement  that the  filenames constructed actually
  5620.             exist.
  5621.  
  5622.                  211 D% echo {zork,gadzooks}.csh
  5623.                  zork.csh gadzooks.csh
  5624.  
  5625.  
  5626.  
  5627.  
  5628.                                      Page 84
  5629.  
  5630.                                                                   Wildcarding
  5631.  
  5632.  
  5633.                  212 D% echo {a,b}{c,d}{e,f}
  5634.                  ace acf ade adf bce bcf bde bdf
  5635.  
  5636.                Alternation can be combined arbitrarily with the other
  5637.             wildcard constructs:
  5638.  
  5639.                  213 D% echo {[bc],*r}*i*
  5640.                  bix brite.csh brite.csh ring.ico
  5641.  
  5642.  
  5643.  
  5644.             Indefinite Directories
  5645.  
  5646.                The  ellipsis,  ``...'',  is  an  indefinite  definite
  5647.             directory wildcard.   It'll  match zero or more arbitrary
  5648.             directory levels -- whatever it takes to make the rest of
  5649.             the wildcard  match.  To be recognized as a wildcard, the
  5650.             context must  indicate it's  really a  filename, i.e., it
  5651.             must be  preceded by  ``\'', ``/'',  ``~''  or  ``:''  or
  5652.             followed by ``\'' or ``/''.  For example, to find all the
  5653.             .inf files anywhere on the C: drive, one might type:
  5654.  
  5655.                  214 D% ls c:\...\*.inf
  5656.                  c:\os2\book\cmdref.inf
  5657.  
  5658.                As with  all the  wildcard constructs,  the indefinite
  5659.             directory construct  can be  used completely arbitrarily.
  5660.             It can  even be  used several times in the same wildcard.
  5661.             But do  notice if  you do that, there is a possibility of
  5662.             getting the same file listed more than once:
  5663.  
  5664.                  215 D% ls f:\...\a*\...\money*
  5665.                  f:\os2\aldus\art\moneycht.eps
  5666.                  f:\os2\aldus\art\moneycht.eps
  5667.  
  5668.                This can  happen if there's more than one possible way
  5669.             to match  the same pathname.  In this example, the ``a*''
  5670.             part could  matched either  ``aldus'' or ``art'' with the
  5671.             first ``...''  matching either  ``os2\aldus'' or  ``os2''
  5672.             and the  second ``...''  matching either  ``art'' or just
  5673.             zero levels.
  5674.  
  5675.  
  5676.  
  5677.             Match Failures
  5678.  
  5679.                When you  specify a  sequence of wildcard patterns and
  5680.             none of  them match,  it's normally  treated as an error.
  5681.             In this  example,  the  first  command  causes  an  error
  5682.             because there's no file or directory name with a ``z'' in
  5683.             it.   The second  command executes without error because,
  5684.             out of  the sequence  of patterns,  there's at  least one
  5685.             match.
  5686.  
  5687.  
  5688.  
  5689.  
  5690.                                      Page 85
  5691.  
  5692.      Wildcarding
  5693.  
  5694.  
  5695.                  216 D% echo *z*
  5696.                  csh:  Wildcarding failed to produce any matches.  To
  5697.                  suppress this error, set nonomatch = 1 (pass
  5698.                  through) or 2 (discard).
  5699.                  217 D% echo *z* sa*
  5700.                  samples
  5701.  
  5702.                In this  context, the  fact  that  alternation  caused
  5703.             something to be generated is not the same as a match.  In
  5704.             the next example, ``{zork,gadzooks,*z*}.csh'' is the same
  5705.             as  ``zork.csh  gadzooks.csh  *z*.csh'';  only  the  last
  5706.             element involves any matching, and it fails.
  5707.  
  5708.                  218 D% echo {zork,gadzooks,*z*}.csh
  5709.                  csh:  Wildcarding failed to produce any matches.  To
  5710.                  suppress this error, set nonomatch = 1 (pass
  5711.                  through) or 2 (discard).
  5712.  
  5713.                The nonomatch variable lets you control how a wildcard
  5714.             failure is  treated.  It works just the way nonovar works
  5715.             when you reference to a non-existent variable.
  5716.  
  5717.                  219 D% set nonomatch = 1
  5718.                  220 D% echo *z*
  5719.                  *z*
  5720.                  221 D% !s:s/1/2/
  5721.                  set nonomatch = 2
  5722.                  222 D% !e
  5723.                  echo *z*
  5724.                  
  5725.                  223 D% !s:s/2/0/
  5726.                  set nonomatch = 0
  5727.                  224 D% !e
  5728.                  echo *z*
  5729.                  csh:  Wildcarding failed to produce any matches.  To
  5730.                  suppress this error, set nonomatch = 1 (pass
  5731.                  through) or 2 (discard).
  5732.  
  5733.  
  5734.  
  5735.             Caution:  The copy, xcopy, rename and del commands
  5736.  
  5737.                Hamilton C  shell  expands  out  wildcards  before  it
  5738.             invokes the  application you  name.  This is not what the
  5739.             copy and  xcopy commands  expect!   Suppose there are two
  5740.             files, file.a  and file.b  on your  diskette a:, that you
  5741.             wanted to  copy to your current drive.  Under cmd.exe, it
  5742.             would be natural to type:
  5743.  
  5744.                  [D:\DOUG] xcopy.exe a:*.*
  5745.                  Source files are being read...
  5746.                  
  5747.                  A:FILE.A
  5748.                  A:FILE.B
  5749.  
  5750.  
  5751.  
  5752.                                      Page 86
  5753.  
  5754.                                                                   Wildcarding
  5755.  
  5756.  
  5757.                  
  5758.                  2 file(s) copied.
  5759.  
  5760.                The destination  is implicit.   xcopy  understands the
  5761.             wildcarding to  mean ``copy everything on drive a: to the
  5762.             current disk  and directory.''   That  is not  what would
  5763.             happen under  the C shell!  Because the wildcard would be
  5764.             expanded first, it would act instead as if you had typed:
  5765.  
  5766.                  [D:\DOUG] xcopy.exe a:file.a a:file.b
  5767.                  Source files are being read...
  5768.                  
  5769.                  A:FILE.A
  5770.                  
  5771.                  1 file(s) copied.
  5772.  
  5773.                Do you  see what  happens?   If  wildcarding  is  done
  5774.             first, the  xcopy command sees just the two filenames and
  5775.             figures you  mean to  copy  one  right  over  the  other.
  5776.             file.b is  lost!  For this reason, the normal startup.csh
  5777.             file contains  some  carefully  constructed  aliases  and
  5778.             procedures to  intercept the  copy, xcopy, rename and del
  5779.             commands:
  5780.  
  5781.                  proc safecopy(files)
  5782.                     cmd /c copy $files; @ nowild = s; unlocal s
  5783.                  end
  5784.                  alias copy   (local s; @ s = nowild; @ nowild = 1;
  5785.                  safecopy)
  5786.                  
  5787.                  proc safexcopy(files)
  5788.                     xcopy.exe $files; @ nowild = s; unlocal s
  5789.                  end
  5790.                  alias xcopy  (local s; @ s = nowild; @ nowild = 1;
  5791.                  safexcopy)
  5792.                  
  5793.                  proc saferename(files)
  5794.                     cmd /c rename $files; @ nowild = s; unlocal s
  5795.                  end
  5796.                  alias rename (local s; @ s = nowild; @ nowild = 1;
  5797.                  saferename)
  5798.                  alias ren    rename
  5799.                  
  5800.                  proc safedel(files)
  5801.                     cmd /c del $files; @ nowild = s; unlocal s
  5802.                  end
  5803.                  alias del      (local s; @ s = nowild; @ nowild = 1;
  5804.                  safedel)
  5805.                  alias erase    del
  5806.  
  5807.                The way  this works  by saving  the current  value  of
  5808.             nowild (which  tells whether  wildcarding  is  should  be
  5809.             done),   turning    off   wildcarding,    invoking    the
  5810.             copy/xcopy/rename/del   command,   then   restoring   the
  5811.  
  5812.  
  5813.  
  5814.                                      Page 87
  5815.  
  5816.      Wildcarding
  5817.  
  5818.  
  5819.             wildcarding state.   s  is a temporary variable that gets
  5820.             discarded after its been used.
  5821.  
  5822.                Be sure  to always  invoke copy,  xcopy rename and del
  5823.             via these  aliases.   If you encounter other applications
  5824.             that really  must do their own wildcarding, use this same
  5825.             technique with them.
  5826.  
  5827.  
  5828.  
  5829.  
  5830.  
  5831.  
  5832.  
  5833.  
  5834.  
  5835.  
  5836.  
  5837.  
  5838.  
  5839.  
  5840.  
  5841.  
  5842.  
  5843.  
  5844.  
  5845.  
  5846.  
  5847.  
  5848.  
  5849.  
  5850.  
  5851.  
  5852.  
  5853.  
  5854.  
  5855.  
  5856.  
  5857.  
  5858.  
  5859.  
  5860.  
  5861.  
  5862.  
  5863.  
  5864.  
  5865.  
  5866.  
  5867.  
  5868.  
  5869.  
  5870.  
  5871.  
  5872.  
  5873.  
  5874.  
  5875.  
  5876.                                      Page 88
  5877.  
  5878.                                                                       Editing
  5879.  
  5880.  
  5881.             
  5882.  
  5883.  
  5884.                                      Editing
  5885.  
  5886.  
  5887.                Often, the  text returned  by a  history, variable  or
  5888.             command substitution  isn't quite  what you  want.    For
  5889.             example, you  may want to select only certain words, do a
  5890.             search/replace, or  manipulate  a  filename  that's  been
  5891.             returned.     The  editing   facilities   provide   these
  5892.             capabilities.
  5893.  
  5894.                The examples  in  this  chapter  show  a  sampling  of
  5895.             various combinations  of editing  commands and  types  of
  5896.             substitutions.   There simply  isn't room to show all the
  5897.             possibilities nor  is there  really a  need to:  with two
  5898.             exceptions (``:%''and ``:p''), any editing command can be
  5899.             applied against  any substitution  type  or  against  the
  5900.             result of another editing command.
  5901.  
  5902.  
  5903.  
  5904.             Word Selections
  5905.  
  5906.                Editing modifiers  begin with a colon, ``:'', followed
  5907.             by an  editing command.   You  can select words either by
  5908.             number or symbolically:  first, last, all, etc.  Here are
  5909.             examples of  the ``:*'',  ``:$'' and  ``:^'' modifiers to
  5910.             select all, last, and first argument words, respectively.
  5911.             Notice that  any number  of editing  modifiers may strung
  5912.             together.  For example, ``:*:^'' means the first argument
  5913.             word (word  1) of the sequence formed of all the original
  5914.             argument words: i.e., word 2.
  5915.  
  5916.                  225 D% echo Finally, now is the time
  5917.                  Finally, now is the time
  5918.                  226 D% echo !!:$
  5919.                  time
  5920.                  227 D% echo !?Fin:*:^
  5921.                  echo now
  5922.                  now
  5923.  
  5924.                It is  also  possible  to  select  words  by  indexing
  5925.             through the  array associated  with a given substitution.
  5926.             The words are counted from zero.
  5927.  
  5928.                  228 D% echo `echo now is the time`:2
  5929.                  the
  5930.  
  5931.                Ranges of  words can  also be  specified with a hyphen
  5932.             between the  beginning and  ending word indices.  In this
  5933.             context,  the   minus  sign   indicates  a   range,   not
  5934.             subtraction.
  5935.  
  5936.  
  5937.  
  5938.                                      Page 89
  5939.  
  5940.      Editing
  5941.  
  5942.  
  5943.                  229 D% set x = now is the time for all good men
  5944.                  230 D% echo $x:1-5
  5945.                  is the time for all
  5946.  
  5947.                When   the   operand   is   a   ``!?''-style   history
  5948.             substitution, there's  a special  operator,  ``:%'',  for
  5949.             selecting the particular word that triggered the match:
  5950.  
  5951.                  231 D% echo !?Fin:%
  5952.                  echo Finally
  5953.                  Finally
  5954.  
  5955.                Each of  the three  symbolic  word  selectors,  ``^'',
  5956.             ``$'' and  ``%'', can  be used  anywhere a  decimal  word
  5957.             number would be acceptable.  For example:
  5958.  
  5959.                  232 D% echo !?time:%-$
  5960.                  echo time for all good men
  5961.                  time for all good men
  5962.  
  5963.  
  5964.  
  5965.             Search/Replace Operations
  5966.  
  5967.                A search/replace  operation looks  for and  replaces a
  5968.             simple character  string.   (For those familiar with such
  5969.             things, it  does not  use regular  expressions.)   If the
  5970.             search string isn't given, the one used last time is used
  5971.             again.   If the  replace string  contains  an  ampersand,
  5972.             ``&'', that  isn't  escaped  with  the  circumflex,  it's
  5973.             expanded  into  the  search  string.    Here  are  a  few
  5974.             examples.  Notice that putting a ``g'' at the start of an
  5975.             operation makes it ``global.''
  5976.  
  5977.                  233 D% echo !?now:%-$:s/o/O/
  5978.                  echo nOw is the time for all good men
  5979.                  nOw is the time for all good men
  5980.                  234 D% !!:gs/t/T/
  5981.                  echo nOw is The Time for all good men
  5982.                  nOw is The Time for all good men
  5983.                  235 D% !!:s/nOw is/& really/
  5984.                  echo nOw is The Time for all good men
  5985.                  nOw is really The Time for all good men
  5986.  
  5987.  
  5988.  
  5989.             Pathname Editing
  5990.  
  5991.                Another set of operators allows filenames to be easily
  5992.             manipulated.     As  with  the  search/replace  operator,
  5993.             pathname editing  is normally  applied to  only the first
  5994.             operand word;  if you want the operation performed on all
  5995.             the words, you must make it global.  In this example, the
  5996.  
  5997.  
  5998.  
  5999.  
  6000.                                      Page 90
  6001.  
  6002.                                                                       Editing
  6003.  
  6004.  
  6005.             ``:h'' (head) operator is used, which returns the name of
  6006.             the directory containing the given file.
  6007.  
  6008.                  236 D% echo *\a*.c
  6009.                  samples\args.c sh\allocate.c
  6010.                  237 D% set dotc = !$
  6011.                  set dotc = *\a*.c
  6012.                  238 D% echo $dotc
  6013.                  samples\args.c sh\allocate.c
  6014.                  239 D% echo $dotc:h
  6015.                  samples sh\allocate.c
  6016.                  240 D% echo $dotc:gh
  6017.                  samples sh
  6018.  
  6019.  
  6020.  
  6021.             Specialized Operations
  6022.  
  6023.                Specialized operations  are provided  for  scanning  a
  6024.             character string  and  breaking  it  up  into  words  and
  6025.             applying quotes around each word.
  6026.  
  6027.                The ``:x''  operator for  breaking up  a  string  into
  6028.             words is  particularly useful  for parsing text read with
  6029.             the getline  pseudo-variable, which  always  returns  the
  6030.             line read as a single character string:
  6031.  
  6032.                  241 D% @ data = $<
  6033.                  (I typed -->this<-- in)
  6034.                  242 D% echo $#data $data
  6035.                  1 (I typed -->this<-- in)
  6036.                  243 D% set data = $data:x
  6037.                  244 D% echo $#data $data
  6038.                  10 ( I typed -- > this < -- in )
  6039.  
  6040.                The ``:q''  operator pastes  single quote marks around
  6041.             every word  in the  operand list.   As  we'll see  in the
  6042.             chapter on  quoting, this  prevents any further wildcard,
  6043.             variable or command substitutions from being done.
  6044.  
  6045.                  245 D% echo sa?pl?s *\a*.c
  6046.                  samples samples\args.c sh\allocate.c
  6047.                  246 D% echo !*:q
  6048.                  echo 'sa?pl?s' '*\a*.c'
  6049.                  sa?pl?s *\a*.c
  6050.  
  6051.  
  6052.  
  6053.             History Edits
  6054.  
  6055.                For history  substitutions, the ``:p'' operator can be
  6056.             used to  cause the  result of the history substitution to
  6057.             be echoed  and entered  into the history list but for the
  6058.             command not  to be executed.  This is helpful when you're
  6059.  
  6060.  
  6061.  
  6062.                                      Page 91
  6063.  
  6064.      Editing
  6065.  
  6066.  
  6067.             trying a  complicated edit  and not sure if the result is
  6068.             going to be what you want.
  6069.  
  6070.                  247 D% !?Fin:p
  6071.                  echo Finally
  6072.                  248 D% !!
  6073.                  echo Finally
  6074.                  Finally
  6075.                  249 D% _
  6076.  
  6077.  
  6078.  
  6079.  
  6080.  
  6081.  
  6082.  
  6083.  
  6084.  
  6085.  
  6086.  
  6087.  
  6088.  
  6089.  
  6090.  
  6091.  
  6092.  
  6093.  
  6094.  
  6095.  
  6096.  
  6097.  
  6098.  
  6099.  
  6100.  
  6101.  
  6102.  
  6103.  
  6104.  
  6105.  
  6106.  
  6107.  
  6108.  
  6109.  
  6110.  
  6111.  
  6112.  
  6113.  
  6114.  
  6115.  
  6116.  
  6117.  
  6118.  
  6119.  
  6120.  
  6121.  
  6122.  
  6123.  
  6124.                                      Page 92
  6125.  
  6126.                                                                       Editing
  6127.  
  6128.  
  6129.             
  6130.  
  6131.  
  6132.  
  6133.  
  6134.  
  6135.  
  6136.  
  6137.  
  6138.  
  6139.  
  6140.  
  6141.  
  6142.  
  6143.  
  6144.  
  6145.  
  6146.  
  6147.  
  6148.  
  6149.  
  6150.  
  6151.  
  6152.  
  6153.  
  6154.  
  6155.  
  6156.  
  6157.  
  6158.  
  6159.  
  6160.  
  6161.  
  6162.  
  6163.  
  6164.  
  6165.  
  6166.  
  6167.  
  6168.  
  6169.  
  6170.  
  6171.  
  6172.  
  6173.  
  6174.  
  6175.  
  6176.  
  6177.  
  6178.  
  6179.  
  6180.  
  6181.  
  6182.  
  6183.  
  6184.  
  6185.  
  6186.                                      Page 93
  6187.  
  6188.      Quoting
  6189.  
  6190.  
  6191.             
  6192.  
  6193.  
  6194.                                      Quoting
  6195.  
  6196.  
  6197.                The shell has several quoting mechanisms for marking a
  6198.             section of  a command  for special  processing.   One  of
  6199.             them, command  substitution, which used the `...` syntax,
  6200.             was already  discussed in the chapter on i/o redirection;
  6201.             that discussion won't be repeated here.
  6202.  
  6203.                The other  quoting mechanisms focus more simply on the
  6204.             problem of  overriding the  special meanings that certain
  6205.             characters have.
  6206.  
  6207.  
  6208.  
  6209.             Double Quotes
  6210.  
  6211.                Double quotes  are of  use when  you want  to  pass  a
  6212.             character  string   containing  a  space  or  other  word
  6213.             separator to an application.  Normally, if you called a C
  6214.             program, it  would  see  these  words  as  separate  argv
  6215.             entries instead  a single character string; double quotes
  6216.             prevents this  breakup into  words.   We can  demonstrate
  6217.             this using  the simple  myecho  program  in  the  samples
  6218.             directory which prints out the argv list it receives with
  6219.             single quotes around each entry:
  6220.  
  6221.                  249 D% cd ~\samples
  6222.                  250 D% myecho hello world
  6223.                  'myecho' 'hello' 'world'
  6224.                  arg length = 19 characters
  6225.                  251 D% myecho "hello world"
  6226.                  'myecho' 'hello world'
  6227.                  arg length = 19 characters
  6228.  
  6229.                Double quotes also turn off the special meaning of the
  6230.             various wildcard characters and the single quote:
  6231.  
  6232.                  252 D% echo "* isn't a wildcard character inside
  6233.                  quotes"
  6234.                  * isn't a wildcard character inside quotes
  6235.                  253 D% echo "~"
  6236.                  ~
  6237.                  254 D% _
  6238.  
  6239.                Command, history  and  variable  substitutions  inside
  6240.             double quotes are still done:
  6241.  
  6242.                  254 D% echo "*** The home directory is $home ***"
  6243.                  *** The home directory is d:\doug ***
  6244.                  255 D% echo "`echo ~`"
  6245.  
  6246.  
  6247.  
  6248.                                      Page 94
  6249.  
  6250.                                                                       Quoting
  6251.  
  6252.  
  6253.                  d:\doug
  6254.                  256 D% echo "myecho.c is `wc -l < myecho.c` lines
  6255.                  long"
  6256.                  myecho.c is 24 lines long
  6257.                  257 D% echo "!?samples"
  6258.                  echo "cd ~\samples"
  6259.                  cd ~\samples
  6260.  
  6261.  
  6262.  
  6263.             Single Quotes
  6264.  
  6265.                Single quotes  are a  little more  brute force to turn
  6266.             off special  meanings.   Wildcards, variables and command
  6267.             substitutions are  all treated  as ordinary  text.   Only
  6268.             history references are recognized inside single quotes.
  6269.  
  6270.                  258 D% echo '*'
  6271.                  *
  6272.                  259 D% echo '$cwd'
  6273.                  $cwd
  6274.                  260 D% echo '`echo hello`"
  6275.                  `echo hello`
  6276.                  261 D% echo '!?samples'
  6277.                  echo 'echo "cd ~\samples"'
  6278.                  echo "cd ~\samples"
  6279.                  262 D% _
  6280.  
  6281.                It is  not necessary  to quote  an entire  word.  It's
  6282.             possible (and  often useful) to selectively quote just as
  6283.             much as  desired.   The quoting  characters are processed
  6284.             out just before invoking the command.  Example:
  6285.  
  6286.                  263 D% echo 'no'w is "t"h'e' `echo time`
  6287.                  now is the time
  6288.  
  6289.  
  6290.  
  6291.             Shell Escape Character
  6292.  
  6293.                The   shell   escape   character   is   normally   the
  6294.             circumflex+, ``^''.   It  has two uses:  preceding any of
  6295.             the  special   characters,  it  turns  off  that  special
  6296.             meaning.  When followed by an alphabetic character or hex
  6297.             or octal  number, it  can be used to enter binary data or
  6298.             characters that  couldn't easily  be typed.    To  get  a
  6299.  
  6300.             ____________________
  6301.             + The circumflex  was chosen  as the default shell escape
  6302.               character  to  be  consistent  with  OS/2  conventions.
  6303.               Choosing  the   Unix  backslash   instead  would   have
  6304.               conflicted  badly   with  OS/2   filename  conventions.
  6305.               Nonetheless, the  escapesym  variable  does  allow  the
  6306.               adventuresome to make a different choice.
  6307.  
  6308.  
  6309.  
  6310.                                      Page 95
  6311.  
  6312.      Quoting
  6313.  
  6314.  
  6315.             literal escape  character, type  two escapes  in  a  row.
  6316.             These specific escape sequences have special meaning:
  6317.  
  6318.                  ^a   Audible Alert (Bell)     ^r   Carriage Return
  6319.                  ^b   BackSpace                ^t   Tab
  6320.                  ^f   Form Feed                ^v   Vertical Tab
  6321.                  ^n   NewLine                  ^^   Single escapesym
  6322.  
  6323.                At the  very end  of a  line, the escape has a special
  6324.             meaning:  the next line is a continuation line.  Inside a
  6325.             quoted string,  the  ``^''-newline  combination  will  be
  6326.             replaced  with  a  simple  newline;  anywhere  else,  the
  6327.             combination is  just turned  into a  space.    The  other
  6328.             special case is when it immediately follows ``[''.  Since
  6329.             ``[^...]'' is  a wildcard  exclusion range,  the ``^'' in
  6330.             this case  is treated as a literal character so you won't
  6331.             have to type two of them in a row.
  6332.  
  6333.                Escape characters  work even  inside single  or double
  6334.             quotes.
  6335.  
  6336.                  263 D% echo now ^
  6337.                  is the time
  6338.                  now is the time
  6339.                  264 D% echo "now ^
  6340.                  is the time"
  6341.                  now
  6342.                  is the time
  6343.                  265 D% _
  6344.  
  6345.  
  6346.  
  6347.             Quoting just part of a Word
  6348.  
  6349.                It's possible to combine the quoting mechanisms or use
  6350.             them on  just the  part of a string you want quoted.  For
  6351.             example,
  6352.  
  6353.                  265 D% echo '$cwd='$cwd
  6354.                  $cwd=d:\doug
  6355.  
  6356.                Here's another  example, searching through a series of
  6357.             .csh files,  looking  for  those  that  are  self-loading
  6358.             procedures.  For example, we can spot that whereis.csh is
  6359.             self-loading because it contains a line like this:
  6360.  
  6361.                  whereis $argv
  6362.  
  6363.             To look  for occurrences  of this  sort,  we  might  loop
  6364.             through a  list of  .csh files,  grep'ing  each  for  the
  6365.             filename  (minus   the  directory   and  .csh  extension)
  6366.             followed by white space followed by ``$argv'':
  6367.  
  6368.  
  6369.  
  6370.  
  6371.  
  6372.                                      Page 96
  6373.  
  6374.                                                                       Quoting
  6375.  
  6376.  
  6377.                  266 D% foreach i (~\samples\*.csh)
  6378.                  267 D?    grep $i:b'[ ^t]*$argv' $i
  6379.                  268 D? end
  6380.                  bits $argv
  6381.                  bumpdate $argv
  6382.                  caldate $argv
  6383.                  calendar $argv
  6384.                  :
  6385.  
  6386.             Notice how  the ``$i:b''  part is  outside the  quotes so
  6387.             that the  filename can  be substituted  in and  edited to
  6388.             strip off  the directory  and extension.  Conversely, the
  6389.             ``[ ^t]*'' and  ``$argv'' portions  are inside the quotes
  6390.             to avoid  having them  confused as a wildcard or variable
  6391.             substitution, respectively.
  6392.  
  6393.  
  6394.  
  6395.             Wildcarding with Special Characters
  6396.  
  6397.                If you'd  like to wildcard filenames that have literal
  6398.             $'s, ['s,  quotes or spaces (under HPFS) or other special
  6399.             characters, you'll  have to  quote or  escape the special
  6400.             characters to  turn off  their  special  meanings.    For
  6401.             example,
  6402.  
  6403.                  269 D% ls g:\tmp
  6404.                  $abc          [hello          this name has spaces
  6405.                  270 D% ls '$'*
  6406.                  $abc
  6407.                  271 D% ls *^ *
  6408.                  this name has spaces
  6409.  
  6410.  
  6411.  
  6412.  
  6413.  
  6414.  
  6415.  
  6416.  
  6417.  
  6418.  
  6419.  
  6420.  
  6421.  
  6422.  
  6423.  
  6424.  
  6425.  
  6426.  
  6427.  
  6428.  
  6429.  
  6430.  
  6431.  
  6432.  
  6433.  
  6434.                                      Page 97
  6435.  
  6436.      Expressions
  6437.  
  6438.  
  6439.             
  6440.  
  6441.  
  6442.                                    Expressions
  6443.  
  6444.  
  6445.                As we've  seen, sometimes a character like ``*'' means
  6446.             wildcard and sometimes it means multiply.  The meaning of
  6447.             what you  type is  determined by  the context.  The shell
  6448.             makes a distinction between words, used as arguments to a
  6449.             command versus an expression context.
  6450.  
  6451.                In general,  expressions  are  expected  wherever  the
  6452.             context would  seem to  suggest that  it  would  be  more
  6453.             natural to  think of  calculating a  value as  opposed to
  6454.             using wildcarding to produce a list of filenames.
  6455.  
  6456.  
  6457.  
  6458.             Expressions
  6459.  
  6460.                The shell's expression grammar is based on that of the
  6461.             C language  and provides  the full  range of  arithmetic,
  6462.             logical,   bit,   indexing   and   relation-testing   and
  6463.             assignment operators.  In addition, there are file system
  6464.             tests and  pattern matching  string compares.  To use the
  6465.             shell as simple calculator, use the calc statement.  This
  6466.             example shows  a call  to the square root routine, one of
  6467.             the built-in procedures.
  6468.  
  6469.                  272 D% calc sqrt(2*pi)
  6470.                  2.506628
  6471.  
  6472.             which writes its result to stdout.  If you want to do the
  6473.             calculation silently, use the ``@'' variant:+
  6474.  
  6475.                  273 D% @ r = 12
  6476.                  274 D% @ area = pi * r**2
  6477.                  275 D% calc area
  6478.                  452.389345
  6479.  
  6480.                In addition  to  the  calc  and  @  statements,  other
  6481.             examples  where  an  expression  is  expected  include  a
  6482.             variable index  inside ``[...]'' brackets, in a procedure
  6483.             argument  list  and,  as  we'll  see,  a  number  of  the
  6484.             structured  programming   constructs  such   as  the  for
  6485.             statement.
  6486.  
  6487.  
  6488.  
  6489.             Expression Parsing
  6490.  
  6491.             ____________________
  6492.             + The choice of @ is a pun:  ``at-sign-ment'' statement.
  6493.  
  6494.  
  6495.  
  6496.                                      Page 98
  6497.  
  6498.                                                                   Expressions
  6499.  
  6500.  
  6501.                All commands are first broken down into words.  A word
  6502.             is anything  separated by  a space or a tab or one of the
  6503.             following special  strings: &  ,|, ;, >, <, (, ), &&, ||,
  6504.             >> or <<.
  6505.  
  6506.                After a  command line  has already been broken up into
  6507.             words, if  the context  is an  expression,  it's  further
  6508.             broken up  into  tokens.    A  token  is  a  variable  or
  6509.             procedure name, a character or numeric literal, or one of
  6510.             the expression  operators.   Spacing  between  tokens  is
  6511.             more-or-less arbitrary:   for  example, there's certainly
  6512.             no need  to put  spaces around  an arithmetic operator to
  6513.             separate it from a variable name beside it.
  6514.  
  6515.                Tokens are  separated by  any of  these characters  or
  6516.             character pairs:  &, |, ^, +, -, *, /, %, //, =, !, ~, <,
  6517.             >, (,  ), [,  ], ,, :, ;, -A, -D, -H, -S, -d, -e, -f, -o,
  6518.             -w, -x,  -z, ++,  --, **, <<, >>, ==, !=, =~, !~, +=, -=,
  6519.             *=, /=,  %=, //=,  ^= and **=.  The <=, >=, <<=, >>=, &=,
  6520.             and |=  are always  broken up  into separate words before
  6521.             expression parsing  begins; for  consistency, the  parser
  6522.             will accept  any of  ``op='' assignment  operators with a
  6523.             space between the ``op'' and ``='' parts.+
  6524.  
  6525.                Since the  shell knows that any names it encounters in
  6526.             an expression  must refer to variables or procedures it's
  6527.             not necessary  to  use  a  dollar  sign  to  introduce  a
  6528.             variable name.   In fact, you'll find that performance is
  6529.             actually a  bit better  if you  do not use a dollar sign.
  6530.             The reason  is because a $-style variable substitution is
  6531.             evaluated  by   converting  the  internal  value  of  the
  6532.             variable to a string and pasting that into the expression
  6533.             where quite  often the  next step  is just  to convert it
  6534.             right back again into the integer or floating point value
  6535.             it started  out as.  Also, if floating point is involved,
  6536.             you may  notice some  loss  of  precision.    (But  don't
  6537.             misunderstand, it is still perfectly legal to use $-style
  6538.             variable and other substitutions in an expression.)
  6539.  
  6540.                Character literals must appear inside single or double
  6541.             quotes.   Numeric literals  can be  entered  in  decimal,
  6542.             octal or  hex.  Octal numbers can contain only the digits
  6543.             0 through  7 and  must begin  with 0.   Hex  numbers must
  6544.             start with  ``0x'' and contain only 0 through f.  (Either
  6545.             upper or lower case is acceptable.)
  6546.  
  6547.  
  6548.  
  6549.             Expression Operators
  6550.             ____________________
  6551.             + The grammar is not perfectly lr(1):  proper recognition
  6552.               of the  file system  tests and  the assignment operator
  6553.               requires that  parsing decisions in some places have to
  6554.               look ahead two tokens, not just one.
  6555.  
  6556.  
  6557.  
  6558.                                      Page 99
  6559.  
  6560.      Expressions
  6561.  
  6562.  
  6563.                Expressions are  evaluated according  to the  relative
  6564.             precedence of  each operator  in  the  expression.    For
  6565.             example, multiplication  is done  before addition.    The
  6566.             complete precedence hierarchy is shown in tabular form in
  6567.             the language reference.
  6568.  
  6569.                  276 D% calc 2 + 3*5
  6570.                  17
  6571.  
  6572.                Some of  the operators  will  be  foreign,  though  we
  6573.             trust, not  too difficult  to use.  The file system tests
  6574.             are unary  operators.   Each takes  the name of a file or
  6575.             directory and tests it for existence, zero-length or some
  6576.             other interesting characteristic.  Since the operand is a
  6577.             pathname, the  parser temporarily  shifts to word mode to
  6578.             read it  because word mode is more natural for pathnames.
  6579.             The pathname  can include  wildcards and  should  not  be
  6580.             enclosed in  quotes.  In the example that follows, ``-e''
  6581.             tests for  existence; ``-D''  tests whether the name is a
  6582.             directory.
  6583.  
  6584.                  277 D% cd ~\samples
  6585.                  278 D% ls
  6586.                  args.c        colors.csh    factor.csh    mcvisa.csh
  6587.                  readme
  6588.                  args.exe      deltaday.csh  finance.csh   myecho.c
  6589.                  ts.csh
  6590.                  bits.csh      dumpenv.c     getprio.c     myecho.exe
  6591.                  viopaste.c
  6592.                  bumpdate.csh  dumpenv.exe   getprio.exe   newfiles.csh
  6593.                  viopaste.exe
  6594.                  caldate.csh   duplicat.csh  julian.csh    rcode.c
  6595.                  weekday.csh
  6596.                  calendar.csh  easter.csh    makecpgm.csh  rcode.exe
  6597.                  279 D% echo a*c
  6598.                  args.c
  6599.                  280 D% calc -e a*c
  6600.                  1
  6601.                  281 D% calc -D !$
  6602.                  calc -D a*c
  6603.                  0
  6604.  
  6605.  
  6606.  
  6607.             File System Tests
  6608.  
  6609.                The value returned from a file system test is always 1
  6610.             or 0; there are no restrictions on how the value might be
  6611.             used in further calculations.
  6612.  
  6613.                  282 D% calc 1 + (!*) + (-e myecho.c)
  6614.                  calc 1 + ( -D a*c ) + ( -e myecho.c )
  6615.                  2
  6616.  
  6617.  
  6618.  
  6619.  
  6620.                                      Page 100
  6621.  
  6622.                                                                   Expressions
  6623.  
  6624.  
  6625.             Increment and Decrement Operators
  6626.  
  6627.                The unary  incrementing and decrementing operators are
  6628.             ``++'' and  ``--''. Pasting  one in  front of  a variable
  6629.             name bumps the variable, then returns the value.  Pasting
  6630.             one after  the name  bumps the  variable but  returns the
  6631.             prior state.
  6632.  
  6633.                  283 D% calc x = 1
  6634.                  1
  6635.                  284 D% calc ++x
  6636.                  2
  6637.                  285 D% calc x++
  6638.                  2
  6639.                  286 D% calc x
  6640.                  3
  6641.                  287 D% calc --x
  6642.                  2
  6643.  
  6644.  
  6645.  
  6646.             Bit Shifting
  6647.  
  6648.                The ``<<''  and ``>>'' bit shifting operators shift an
  6649.             integer value  on the left by the number of bit positions
  6650.             given by  the integer  value on  the right.  Bits shifted
  6651.             off the end are lost; values shifted in are always 0.
  6652.  
  6653.                  288 D% calc x << 3
  6654.                  8
  6655.                  289 D% calc x >> 10
  6656.                  0
  6657.  
  6658.  
  6659.  
  6660.             Bit Not Operation
  6661.  
  6662.                The unary  ``~'' operator  returns the bit-wise not of
  6663.             an integer  operand.  As this example shows, integers are
  6664.             32-bit signed values.
  6665.  
  6666.                  290 D% calc ~5
  6667.                  -6
  6668.                  291 D% calc 0xfffffffa
  6669.                  -6
  6670.                  292 D% calc ~!$
  6671.                  calc ~0xfffffffa
  6672.                  5
  6673.  
  6674.  
  6675.  
  6676.             Logical Not
  6677.  
  6678.  
  6679.  
  6680.  
  6681.  
  6682.                                      Page 101
  6683.  
  6684.      Expressions
  6685.  
  6686.  
  6687.                The unary  ``!'' operator returns the logical not.  If
  6688.             the operand  is non-zero,  0 is returned, otherwise 1. In
  6689.             this  example,   the  parentheses   or  space  after  the
  6690.             exclamation are deliberate to avoid having the expression
  6691.             confused as a history reference.
  6692.  
  6693.                  293 D% calc !(5.1)
  6694.                  0
  6695.                  294 D% calc ! 0
  6696.                  1
  6697.  
  6698.  
  6699.  
  6700.             Exponentiation
  6701.  
  6702.                The ``**''  operator is  for exponentiation.  The left
  6703.             operand is raised to power of the right operand.
  6704.  
  6705.                  295 D% calc 2 ** 500
  6706.                  3.27339061e+150
  6707.  
  6708.  
  6709.  
  6710.             Modulo and Integer Division
  6711.  
  6712.                The ``%''  operator is for modulo division and returns
  6713.             the remainder.
  6714.  
  6715.                  296 D% calc 22 % 7
  6716.                  1
  6717.  
  6718.                A  related  ``//''  operator  does  integer  division.
  6719.             Where the standard ``/'' operator might return a floating
  6720.             point result,  ``//'' gives  just the integer part of any
  6721.             division.
  6722.  
  6723.                  297 D% calc 8/3
  6724.                  2.666667
  6725.                  298 D% calc 8//3
  6726.                  2
  6727.  
  6728.  
  6729.  
  6730.             Comparison Operators
  6731.  
  6732.                The ``==''  operator tests  for equality;  the  single
  6733.             ``='' means  assignment.    The  ``!='',  ``<'',  ``<='',
  6734.             ``>='', and  ``>''  operators  are  all  straight-forward
  6735.             tests of  ``not equal,''  ``less than,''  ``less than  or
  6736.             equal,'' etc.   Comparisons  of strings are as easy as of
  6737.             numbers.
  6738.  
  6739.                  299 D% calc x = 3
  6740.                  3
  6741.  
  6742.  
  6743.  
  6744.                                      Page 102
  6745.  
  6746.                                                                   Expressions
  6747.  
  6748.  
  6749.                  300 D% calc x == 5
  6750.                  0
  6751.                  301 D% calc "able" < "baker"
  6752.                  1
  6753.  
  6754.                When the shell is asked to compare two expressions, it
  6755.             first tries to coerce them to numeric values.  This is so
  6756.             that, e.g.,  a string  containing ``16'' compares greater
  6757.             than ``2'' even though a simple string compare would give
  6758.             the opposite result.
  6759.  
  6760.  
  6761.  
  6762.             Pattern Matching Operators
  6763.  
  6764.                The ``=~''and  ``!~'' are  the ``pattern matches'' and
  6765.             ``pattern fails''  tests.   These are done in pretty much
  6766.             the same  way wildcarding  is done.   On  the right  is a
  6767.             pattern string  possibly containing  wildcard characters.
  6768.             It's compared against the string on the left the same way
  6769.             a wildcard  expansion would  be done  except  that  here,
  6770.             comparisons  are  case-sensitive  and  where  alternation
  6771.             appears, the  match succeeds  if any  of  the  alternates
  6772.             matches.
  6773.  
  6774.                  302 D% calc "Now is" =~ "N*i*"
  6775.                  1
  6776.                  303 D% calc "Now is" !~ "Now is"
  6777.                  0
  6778.                  304 D% calc "Now is" =~ "n*i*"
  6779.                  0
  6780.                  305 D% calc "Now is" =~ "{n,No}*i{s,the}"
  6781.                  1
  6782.  
  6783.  
  6784.  
  6785.             Bitwise And, Xor and Or Operators
  6786.  
  6787.                The ``&'',  ``^'' and ``|'' operators perform bit-wise
  6788.             and, xor and or operations on integer operands.
  6789.  
  6790.                  306 D% calc 5 & 4
  6791.                  4
  6792.                  307 D% calc 5 ^ 3
  6793.                  6
  6794.                  308 D% calc 5 | 3
  6795.                  7
  6796.  
  6797.  
  6798.  
  6799.             Logical And and Or
  6800.  
  6801.                The ``&&''  and ``||''  operators perform  logical and
  6802.             and or operations:
  6803.  
  6804.  
  6805.  
  6806.                                      Page 103
  6807.  
  6808.      Expressions
  6809.  
  6810.  
  6811.                  309 D% calc 5 && 4
  6812.                  1
  6813.                  310 D% calc 0 && 4
  6814.                  0
  6815.                  311 D% calc 5 || 3
  6816.                  1
  6817.                  312 D% calc 5 || 0
  6818.                  1
  6819.  
  6820.  
  6821.  
  6822.             The ?: Operator
  6823.  
  6824.                The  ``?:''   trinary  operator  selects  between  two
  6825.             alternate expressions based on the logical (i.e., true or
  6826.             false) value of the first operand.
  6827.  
  6828.                  313 D% calc 0 ? "hello" : "goodby"
  6829.                  goodby
  6830.                  314 D% calc (5 > 3) ? "hit" : "miss"
  6831.                  hit
  6832.  
  6833.  
  6834.  
  6835.             The {...} Operator
  6836.  
  6837.                The ``{...}''  grouping operator  allows you  to run a
  6838.             command and  evaluate its result as a 1 if it succeeds or
  6839.             a zero if it fails.  For example:
  6840.  
  6841.                  315 D% calc {echo hello}
  6842.                  hello
  6843.                  1
  6844.                  316 D% calc {cd \nonexistent}
  6845.                  csh:  Couldn't change the current directory to
  6846.                  '\nonexistent'.
  6847.                  0
  6848.  
  6849.  
  6850.  
  6851.             The Op= Operators
  6852.  
  6853.                Finally, the various ``op='' operators apply the op to
  6854.             the left  and right  operands, then  assign the result to
  6855.             the left operand.
  6856.  
  6857.                  317 D% calc x = 2
  6858.                  2
  6859.                  318 D% calc x **= 500
  6860.                  3.27339061e+150
  6861.                  319 D% calc x
  6862.                  3.27339061e+150
  6863.  
  6864.  
  6865.  
  6866.  
  6867.  
  6868.                                      Page 104
  6869.  
  6870.                                                                   Expressions
  6871.  
  6872.  
  6873.             Type Conversions
  6874.  
  6875.                The  shell   always  tries   to  evaluate  expressions
  6876.             ``sensibly'' by  doing any  type conversions  that  might
  6877.             seem necessary.   If an integer calculation results in an
  6878.             overflow, the  shell  shifts  automatically  to  floating
  6879.             point.
  6880.  
  6881.                  320 D% calc 2**30
  6882.                  1073741824
  6883.                  321 D% calc 2**200
  6884.                  1.606938e+060
  6885.  
  6886.                If a  character string  was given  but an  integer  is
  6887.             needed, the  shell tries  to  do  that  conversion  also.
  6888.             Because these  conversions happen  automatically, without
  6889.             any fanfare, the following literals all compare equal:
  6890.  
  6891.                  27    27.0    033    0x1B    " 27 "    '   0x1b '
  6892.  
  6893.             (Null strings  and strings consisting only of white space
  6894.             are considered  equal to  zero.    This  is  particularly
  6895.             convenient for  local variables,  which are initially set
  6896.             to null strings.)
  6897.  
  6898.                The shell  does automatic  conversions to  a character
  6899.             string format  when the result is being printed.  Numeric
  6900.             results are  always shown in decimal.  In this example, a
  6901.             procedure, the  built-in square  root routine, is invoked
  6902.             as a  command; the  value it  returns is  converted  from
  6903.             floating point to character string and printed.
  6904.  
  6905.                  322 D% sqrt 2
  6906.                  1.414213
  6907.  
  6908.                 The  shell also  converts to  a character string when
  6909.             you reference an array but use it as if it were not.
  6910.  
  6911.                  323 D% set x = Now is the time
  6912.                  324 D% cd ~\samples; myecho $x
  6913.                  'myecho' 'Now' 'is' 'the' 'time'
  6914.                  arg length = 23 characters
  6915.                  325 D% @ y = x
  6916.                  326 D% myecho $y
  6917.                  'myecho' 'Now is the time'
  6918.                  arg length = 23 characters
  6919.  
  6920.  
  6921.  
  6922.  
  6923.  
  6924.  
  6925.  
  6926.  
  6927.  
  6928.  
  6929.  
  6930.                                      Page 105
  6931.  
  6932.      Expressions
  6933.  
  6934.  
  6935.             
  6936.  
  6937.  
  6938.  
  6939.  
  6940.  
  6941.  
  6942.  
  6943.  
  6944.  
  6945.  
  6946.  
  6947.  
  6948.  
  6949.  
  6950.  
  6951.  
  6952.  
  6953.  
  6954.  
  6955.  
  6956.  
  6957.  
  6958.  
  6959.  
  6960.  
  6961.  
  6962.  
  6963.  
  6964.  
  6965.  
  6966.  
  6967.  
  6968.  
  6969.  
  6970.  
  6971.  
  6972.  
  6973.  
  6974.  
  6975.  
  6976.  
  6977.  
  6978.  
  6979.  
  6980.  
  6981.  
  6982.  
  6983.  
  6984.  
  6985.  
  6986.  
  6987.  
  6988.  
  6989.  
  6990.  
  6991.  
  6992.                                      Page 106
  6993.  
  6994.                                                                       Aliases
  6995.  
  6996.  
  6997.             
  6998.  
  6999.  
  7000.                                      Aliases
  7001.  
  7002.  
  7003.                Aliases are  a quick shorthand technique.  If you type
  7004.             an alias  at the beginning of a command, it's replaced by
  7005.             whatever the alias is defined as.  They're intended to be
  7006.             used  for   relatively  simple  abbreviations:    if  any
  7007.             arguments are  needed, you  have to  be able to type them
  7008.             onto the end.  (More complex situations will have to wait
  7009.             until we cover procedures.)
  7010.  
  7011.                To list  the aliases  currently defined, use the alias
  7012.             command:
  7013.  
  7014.                  327 D% alias
  7015.                  cdd          cd +c
  7016.                  copy         local s ; @ s = nowild ; @ nowild = 1 ;
  7017.                  safecopy
  7018.                  date         dt
  7019.                  del          local s ; @ s = nowild ; @ nowild = 1 ;
  7020.                  safedel
  7021.                  dir          cmd /c dir
  7022.                  erase        del
  7023.                  h            history
  7024.                  help         helpmsg
  7025.                  label        cmd /c label
  7026.                  ll           ls -L
  7027.                  md           mkdir
  7028.                  mi           more -i
  7029.                  rd           rmdir
  7030.                  ren          rename
  7031.                  rename       local s ; @ s = nowild ; @ nowild = 1 ;
  7032.                  saferename
  7033.                  ro           rotd
  7034.                  start        cmd /c start
  7035.                  type         cat
  7036.                  vol          vl
  7037.                  xcopy        local s ; @ s = nowild ; @ nowild = 1 ;
  7038.                  safexcopy
  7039.  
  7040.                Some aliases  are  used  to  intercept  references  to
  7041.             cmd.exe's built-in  commands.   For example,  this is how
  7042.             dir is run.  Other aliases give simple alternate names to
  7043.             a command, e.g., rename for mv.  Still others are used to
  7044.             customize a  command with  a useful option.  For example,
  7045.             mi runs  more but  starts it  immediately in  interactive
  7046.             mode, which  means the  screen is  cleared first; in a PM
  7047.             text window, this tends to run faster.
  7048.  
  7049.  
  7050.  
  7051.  
  7052.  
  7053.  
  7054.                                      Page 107
  7055.  
  7056.      Aliases
  7057.  
  7058.  
  7059.                To find  out how  any particular alias is defined, use
  7060.             the alias command with only the name you're interested in
  7061.             as an operand.
  7062.  
  7063.                  328 D% alias mi
  7064.                  mi           more -i
  7065.  
  7066.                To create a new alias, type the alias command followed
  7067.             by the  name of  alias being  created and  word  list  it
  7068.             should be expanded into:
  7069.  
  7070.                  329 D% alias hello echo hello world
  7071.                  330 D% hello
  7072.                  hello world
  7073.  
  7074.                If you  define an  alias that refers to itself, either
  7075.             directly or  via  other  aliases,  the  shell  traps  the
  7076.             reference rather  than  allowing  it  to  expand  without
  7077.             limit:
  7078.  
  7079.                  331 D% alias hello (echo infinite; hello again)
  7080.                  332 D% hello
  7081.                  csh:  A loop in the alias definitions was
  7082.                  encountered and trapped.
  7083.  
  7084.                This raises  the question  how  you  might  define  an
  7085.             alias, say,  ls, that  intercepts references  to  the  ls
  7086.             utility without  getting into a loop.  The answer is that
  7087.             the shell  considers it  a special case if the first word
  7088.             in the  expansion of  the alias  is the same as its name.
  7089.             Here's an  alias that  causes ls  to always  display  all
  7090.             files:
  7091.  
  7092.                  333 D% alias ls ls +a
  7093.  
  7094.             Other ways  around the  problem would  be to use the full
  7095.             ``ls.exe'' name inside the alias or put quotes around the
  7096.             ``ls''.
  7097.  
  7098.  
  7099.  
  7100.             Wildcards and Special Characters in an Alias
  7101.  
  7102.                Recall that  any wildcards  or escape  characters in a
  7103.             command are always processed before the command itself is
  7104.             run.   Suppose you  wanted to define an alias to list all
  7105.             your .exe  files in  the current  directory.   Watch what
  7106.             happens if we're not careful:
  7107.  
  7108.                  334 D% cd
  7109.                  d:\hamilton\samples
  7110.                  335 D% alias lexe ls *.exe
  7111.                  336 D% lexe
  7112.                  args.exe          dumpenv.exe       rcode.exe
  7113.  
  7114.  
  7115.  
  7116.                                      Page 108
  7117.  
  7118.                                                                       Aliases
  7119.  
  7120.  
  7121.                  blksize.exe       myecho.exe        winerror.exe
  7122.                  337 D% cd ..\bin
  7123.                  338 D% lexe
  7124.                  ls:  'args.exe' does not exist.
  7125.                  ls:  'blksize.exe' does not exist.
  7126.                  ls:  'dumpenv.exe' does not exist.
  7127.                  ls:  'myecho.exe' does not exist.
  7128.                  ls:  'rcode.exe' does not exist.
  7129.                  ls:  'winerror.exe' does not exist.
  7130.  
  7131.                What happened?   Why  didn't lexe give us the files in
  7132.             our new  current directory?   The  answer is  clear if we
  7133.             list the alias definition:
  7134.  
  7135.                  339 D% alias lexe
  7136.                  lexe         ls args.exe blksize.exe dumpenv.exe
  7137.                  myecho.exe rcode.exe winerror.exe
  7138.  
  7139.                The ``*.exe''  wildcard got  expanded before the alias
  7140.             definition was processed.  If we want to defer processing
  7141.             of the  wildcard until  later, when the alias is used, we
  7142.             need to escape the ``*'' character:
  7143.  
  7144.                  340 D% alias lexe ls ^*.exe
  7145.                  341 D% alias lexe
  7146.                  lexe         ls *.exe
  7147.  
  7148.                It's just a little trickier if we want to turn off the
  7149.             special meaning not only when defining the alias but also
  7150.             when we use it.  That's done by embedding an extra ``^^''
  7151.             sequence into  what we  type, knowing that'll turn into a
  7152.             single escape  character in  the definition.   Here's  an
  7153.             example:
  7154.  
  7155.                  342 D% alias hello echo How are you^^^?
  7156.                  343 D% alias hello
  7157.                  hello        How are you^?
  7158.                  344 D% hello
  7159.                  How are you?
  7160.  
  7161.  
  7162.  
  7163.             Arguments to Aliases
  7164.  
  7165.                Normally,  any   words  on   the  line  following  the
  7166.             reference to  the alias  will simply  be tacked  onto the
  7167.             expansion.  For example:
  7168.  
  7169.                  345 D% alias hello echo hello world
  7170.                  346 D% hello how are you
  7171.                  hello world how are you
  7172.  
  7173.                But suppose you'd like to paste the arguments into the
  7174.             middle of  the expansion?   The  way to do that is with a
  7175.  
  7176.  
  7177.  
  7178.                                      Page 109
  7179.  
  7180.      Aliases
  7181.  
  7182.  
  7183.             very special adaptation of the history mechanism.  If the
  7184.             expansion contains  any history  references, the  C shell
  7185.             treats this  as a  special case.  It temporarily adds the
  7186.             original text  of that command to the history list.  Note
  7187.             that only  the command  itself -- starting with the alias
  7188.             name  and  ending  just  before  any  semicolon,  closing
  7189.             parenthesis or pipe symbol terminating the command -- not
  7190.             the whole  line is  added.  Any history references in the
  7191.             definition of  the alias  are processed  and  the  result
  7192.             taken as  the final  command text.  The temporary history
  7193.             entry is  then discarded  along the  original  string  of
  7194.             argument words.  Here's an example:
  7195.  
  7196.                  347 D% alias hello echo hi ^!^^, how are you^^^?
  7197.                  348 D% alias hello
  7198.                  hello        echo hi !^ how are you^?
  7199.                  349 D% echo x; hello Frank; echo y
  7200.                  x
  7201.                  hi Frank, how are you?
  7202.                  y
  7203.  
  7204.             Notice the  use of  the escape  characters to  embed  the
  7205.             history reference,  ``!^'' and the literal ``?'' into the
  7206.             alias definition.
  7207.  
  7208.                  It is  not necessary  for the  alias to  use all the
  7209.             argument words.   Any that it doesn't reference using the
  7210.             history mechanism  are just  discarded.  Notice that this
  7211.             alias grabbed  only the first argument word from history.
  7212.             Suppose there were other words on the line:
  7213.  
  7214.                  350 D% hi Frank and Bob
  7215.                  hi Frank, how are you?
  7216.  
  7217.             See how the rest were just discarded?
  7218.  
  7219.  
  7220.  
  7221.             Implementation Details
  7222.  
  7223.                The alias  mechanism is  actually part  of the parsing
  7224.             mechanism rather  than a run-time feature of the C shell.
  7225.             What that  means is that the alias expansion is done when
  7226.             the statement  is first  read, not  when  it's  executed.
  7227.             Here's  an   example  where  we  attempt  to  change  the
  7228.             definition of  an alias  inside a  loop.   Notice that it
  7229.             doesn't have  any effect  until we exit the loop.  That's
  7230.             because the  whole loop  is being  compiled  as  a  block
  7231.             before any part of it is executed.
  7232.  
  7233.                  351 D% alias foo echo this is life
  7234.                  352 D% foreach i (hello world)
  7235.                  353 D?    alias foo echo $i
  7236.                  354 D?    foo
  7237.  
  7238.  
  7239.  
  7240.                                      Page 110
  7241.  
  7242.                                                                       Aliases
  7243.  
  7244.  
  7245.                  355 D? end
  7246.                  this is life
  7247.                  this is life
  7248.                  356 D% foo
  7249.                  world
  7250.  
  7251.                Also,  when   an  alias   substitution  is  done,  the
  7252.             expansion is  taken as  the series of words the alias was
  7253.             defined as;  it's not reparsed into words all over again.
  7254.             For example:
  7255.  
  7256.                  357 D% alias test myecho "this is a test"
  7257.                  358 D% alias test
  7258.                  test         myecho this is a test
  7259.                  359 D% test
  7260.                  'myecho' 'this is a test'
  7261.                  arg length = 22 characters
  7262.  
  7263.                Notice that  you can't  really see that the test alias
  7264.             is  defined   as   just   two   words,   ``myecho''   and
  7265.             ``this is a test'' when  you  list  it  (it's  just  like
  7266.             listing a  variable set  to a list of words some of which
  7267.             contain spaces),  but that's  what it  is.    These  word
  7268.             boundaries are  maintained even  if  the  alias  contains
  7269.             history references.
  7270.  
  7271.  
  7272.  
  7273.  
  7274.  
  7275.  
  7276.  
  7277.  
  7278.  
  7279.  
  7280.  
  7281.  
  7282.  
  7283.  
  7284.  
  7285.  
  7286.  
  7287.  
  7288.  
  7289.  
  7290.  
  7291.  
  7292.  
  7293.  
  7294.  
  7295.  
  7296.  
  7297.  
  7298.  
  7299.  
  7300.  
  7301.  
  7302.                                      Page 111
  7303.  
  7304.      Programming Constructs
  7305.  
  7306.  
  7307.             
  7308.  
  7309.  
  7310.                              Programming Constructs
  7311.  
  7312.  
  7313.                This chapter  outlines the various structures provided
  7314.             for connecting  statements together:   describing  serial
  7315.             relationships, conditional  execution, iteration  and how
  7316.             procedures are defined and used.
  7317.  
  7318.  
  7319.  
  7320.             Serial Execution
  7321.  
  7322.                As we've  seen already,  commands typed  on successive
  7323.             lines  are   executed  serially,  one  after  the  other.
  7324.             Writing several  commands on  one  line  with  semicolons
  7325.             between them does the same thing.
  7326.  
  7327.                  360 D% echo hello; echo world
  7328.                  hello
  7329.                  world
  7330.                  361 D% _
  7331.  
  7332.                Notice that  in contrast to cmd.exe, the shell doesn't
  7333.             pass the semicolon to the application you invoke.  If you
  7334.             really do  want to  pass a semicolon, e.g., to the linker
  7335.             to indicate  the end of the arguments, you have to escape
  7336.             it or put it inside quotes.
  7337.  
  7338.                 A  non-zero return code is not normally considered an
  7339.             error:  regardless of the return code from any particular
  7340.             command, serial  execution continues.  We can demonstrate
  7341.             this with  the rcode  utility in  the  samples  directory
  7342.             which prints,  then exits  with the return code value you
  7343.             pass it on the command line.  This example also shows how
  7344.             you can  retrieve the  return  code  of  the  last  child
  7345.             process by referring to the built-in status variable.
  7346.  
  7347.                  361 D% cd ~\samples
  7348.                  362 D% rcode 1; rcode 2
  7349.                  1
  7350.                  2
  7351.                  363 D% calc status
  7352.                  2
  7353.  
  7354.                It's also  possible to  describe a  conditional serial
  7355.             relationship.   If statements  are joined  by ``&&'', the
  7356.             second one  is executed  only if the return code from the
  7357.             first one  is 0,  i.e., if  the first statement succeeds.
  7358.             If  statements  are  joined  by  ``||'',  the  second  is
  7359.             executed only  if the  first one  fails, i.e.,  returns a
  7360.             non-zero return code.
  7361.  
  7362.  
  7363.  
  7364.                                      Page 112
  7365.  
  7366.                                                        Programming Constructs
  7367.  
  7368.  
  7369.                  364 D% rcode 0 || rcode 1
  7370.                  0
  7371.                  365 D% rcode 1 || rcode 2
  7372.                  1
  7373.                  2
  7374.                  366 D% rcode 0 && rcode 1
  7375.                  0
  7376.                  1
  7377.                  367 D% rcode 1 && rcode 2
  7378.                  1
  7379.  
  7380.  
  7381.  
  7382.             Statements and Statement Lists
  7383.  
  7384.                I/O   redirectors   and   statement   connectors   are
  7385.             recognized  according  to  a  precedence.    Just  as  in
  7386.             expressions, where ``*'' is done before ``+'', statements
  7387.             are parsed  so that  some things  are done before others.
  7388.             I/O redirection  comes before  piping which  comes before
  7389.             conditional execution which comes before serializing with
  7390.             semicolons.  For example:
  7391.  
  7392.                  368 D% echo hello; echo world | wc
  7393.                  hello
  7394.                          1        1        7
  7395.  
  7396.                The  shell   makes  a   special  distinction   between
  7397.             individual statements,  no matter  how complex, and lists
  7398.             of statements  typed on  separate lines  or separated  by
  7399.             semicolons.
  7400.  
  7401.                Here's an example using the time command, which runs a
  7402.             statement and  prints out  the hours, minutes and seconds
  7403.             it took.   time  expects a single statement as a operand;
  7404.             if you  type a semicolon, the time command (together with
  7405.             its operand) becomes just one statement in the list.
  7406.  
  7407.                  369 D% time echo hello world | wc
  7408.                          1        2       13
  7409.                  0:00:00.50
  7410.                  370 D% time echo hello; echo world
  7411.                  hello
  7412.                  0:00:00.00
  7413.                  world
  7414.  
  7415.  
  7416.  
  7417.             Parenthesis
  7418.  
  7419.                There are  two ways  to group  a  list  of  statements
  7420.             together to  make them  act like a single statement.  The
  7421.             simplest way is with parenthesis, which work the way they
  7422.  
  7423.  
  7424.  
  7425.  
  7426.                                      Page 113
  7427.  
  7428.      Programming Constructs
  7429.  
  7430.  
  7431.             would in  an expression:  even if the operator inside the
  7432.             parentheses are of lower precedence, they're done first.
  7433.  
  7434.                  371 D% (echo hello; echo world) | wc
  7435.                          2        2       14
  7436.                  372 D% time (echo hello; echo world)
  7437.                  hello
  7438.                  world
  7439.                  0:00:00.00
  7440.  
  7441.                A parenthesized group gets its own copy of the current
  7442.             directory and  disk.   This makes it convenient to change
  7443.             directories inside  the group and go do something without
  7444.             having to change back afterward.
  7445.  
  7446.                  373 D% cd
  7447.                  d:\doug\samples
  7448.                  374 D% (cd ..; cd)
  7449.                  d:\doug
  7450.                  375 D% cd
  7451.                  d:\doug\samples
  7452.  
  7453.                The actual  implementation uses  the  directory  stack
  7454.             mechanism:   at entry to the group, the current directory
  7455.             is pushed  onto the  directory stack and at exit, the top
  7456.             entry is popped.
  7457.  
  7458.                  376 D% dirs
  7459.                  d:\doug\samples
  7460.                  377 D% ( dirs )
  7461.                  d:\doug\samples
  7462.                  d:\doug\samples
  7463.                  378 D% dirs
  7464.                  d:\doug\samples
  7465.  
  7466.  
  7467.  
  7468.             Control Structures
  7469.  
  7470.                The more general way of connecting statements together
  7471.             is  with   control  structures,  which  provide  ways  of
  7472.             describing conditional  or iterative  execution  or  even
  7473.             (with procedures)  adding new vocabulary to the language.
  7474.             You can  use a  control structure anywhere a statement is
  7475.             allowed.
  7476.  
  7477.                The  language   is  completely   recursive:    control
  7478.             structures can  be nested inside control structures, etc.
  7479.             A statement  can  be  arbitrarily  complex.    Here's  an
  7480.             example timing  a statement  that turns  out to  be a for
  7481.             loop piped to a wc and inside the for loop ...
  7482.  
  7483.                  379 D% time for i = 1 to 3 do
  7484.                  380 D?         time echo hello world | wc
  7485.  
  7486.  
  7487.  
  7488.                                      Page 114
  7489.  
  7490.                                                        Programming Constructs
  7491.  
  7492.  
  7493.                  381 D?      end | wc
  7494.                          6       12      126
  7495.                  0:00:01.03
  7496.  
  7497.  
  7498.  
  7499.             If Statement
  7500.  
  7501.                The if  statement comes  in two forms.  The short form
  7502.             is convenient if the choice is only between executing and
  7503.             not executing  a single  statement, which  appears on the
  7504.             same line.
  7505.  
  7506.                  382 D% if (5 == 2 + 3) echo yes
  7507.                  yes
  7508.                  383 D% if (5 == 10) echo really
  7509.                  384 D% _
  7510.  
  7511.                The longer form provides the more traditional if-then-
  7512.             else structure.   Indentation is a matter of choice, it's
  7513.             used in these examples merely to improve readability.
  7514.  
  7515.                  384 D% if (5 == 10) then
  7516.                  385 D?    echo 5 == 10
  7517.                  386 D? else
  7518.                  387 D?    echo 5 is not 10
  7519.                  388 D? end
  7520.                  5 is not 10
  7521.                  389 D% _
  7522.  
  7523.  
  7524.  
  7525.             Switch Statement
  7526.  
  7527.                The switch  statement works  by attempting  to pattern
  7528.             match the  switch value  against a  series of alternative
  7529.             cases.   The switch  and case values can all be arbitrary
  7530.             expressions.   If any  pattern match  succeeds, execution
  7531.             begins with  the next  statement following and continues,
  7532.             skipping over  any interspersed case clauses until either
  7533.             the end  of the  switch block  or a  break  statement  is
  7534.             reached.
  7535.  
  7536.                  389 D% switch ("hello world")
  7537.                  390 D?    case 5:
  7538.                  391 D?       echo hit 5
  7539.                  392 D?    case "h*":
  7540.                  393 D?       echo hit "h*"
  7541.                  394 D?    case "x*":
  7542.                  395 D?       echo hit "x*"
  7543.                  396 D?       break
  7544.                  397 D?    case 43.2:
  7545.                  398 D?       echo hit 43.2
  7546.                  399 D?    default:
  7547.  
  7548.  
  7549.  
  7550.                                      Page 115
  7551.  
  7552.      Programming Constructs
  7553.  
  7554.  
  7555.                  400 D?       echo did not hit
  7556.                  401 D? end
  7557.                  hit h*
  7558.                  hit x*
  7559.  
  7560.                The break  statement used  here  causes  execution  to
  7561.             ``break out  of'' the  innermost control  structure.   If
  7562.             you're nested several layers deep into control structures
  7563.             and want to break out of a higher level structure you can
  7564.             label the higher level structure and specify that name on
  7565.             the break statement.
  7566.  
  7567.  
  7568.  
  7569.  
  7570.  
  7571.  
  7572.  
  7573.  
  7574.  
  7575.  
  7576.  
  7577.  
  7578.  
  7579.  
  7580.  
  7581.  
  7582.  
  7583.  
  7584.  
  7585.  
  7586.  
  7587.  
  7588.  
  7589.  
  7590.  
  7591.  
  7592.  
  7593.  
  7594.  
  7595.  
  7596.  
  7597.  
  7598.  
  7599.  
  7600.  
  7601.  
  7602.  
  7603.  
  7604.  
  7605.  
  7606.  
  7607.  
  7608.  
  7609.  
  7610.  
  7611.  
  7612.                                      Page 116
  7613.  
  7614.                                                        Programming Constructs
  7615.  
  7616.  
  7617.             Foreach Statement
  7618.  
  7619.                The foreach statement is designed for iterating over a
  7620.             series of words.  In this example, i is iterated over the
  7621.             list of  all the  files in  the samples  directory.  Each
  7622.             one, in  turn, is tested to see if it's executable (i.e.,
  7623.             has a .csh, .cmd, .exe or .com extension.)
  7624.  
  7625.                  402 D% cd ~\samples
  7626.                  403 D% ls
  7627.                  args.c       dumpenv.c    finance.csh  myecho.exe
  7628.                  readme
  7629.                  args.exe     dumpenv.exe  makecpgm.csh rcode.c
  7630.                  bits.csh     factor.csh   myecho.c     rcode.exe
  7631.                  404 D% foreach i (*)
  7632.                  405 D?    if (-x $i) echo $i is executable
  7633.                  406 D? end
  7634.                  args.exe is executable
  7635.                  bits.csh is executable
  7636.                  dumpenv.exe is executable
  7637.                  factor.csh is executable
  7638.                  finance.csh is executable
  7639.                  makecpgm.csh is executable
  7640.                  myecho.exe is executable
  7641.                  rcode.exe is executable
  7642.  
  7643.  
  7644.  
  7645.             For Statement
  7646.  
  7647.                The for  statement provides more traditional iteration
  7648.             over numerical values.  If you specify a range (e.g., ``1
  7649.             to 3'')  but don't  specify the  increment, 1 is assumed.
  7650.             Although  this   example  shows  iteration  over  integer
  7651.             values, floating point values are equally acceptable.
  7652.  
  7653.                  407 D% for i = 1 to 3 do
  7654.                  408 D?    echo $i
  7655.                  409 D? end
  7656.                  1
  7657.                  2
  7658.                  3
  7659.  
  7660.                You  can  also  iterate  over  a  list  of  ranges  or
  7661.             individual  values.    The  to  and  by  clauses  may  be
  7662.             specified in either order.
  7663.  
  7664.                  410 D% for i = 1, 4, 7, 12, -4 to 6 by 3 do
  7665.                  411 D?    echo $i
  7666.                  412 D? end
  7667.                  1
  7668.                  4
  7669.                  7
  7670.                  12
  7671.  
  7672.  
  7673.  
  7674.                                      Page 117
  7675.  
  7676.      Programming Constructs
  7677.  
  7678.  
  7679.                  -4
  7680.                  -1
  7681.                  2
  7682.                  5
  7683.  
  7684.  
  7685.  
  7686.             While Statement
  7687.  
  7688.                The while  statement works  in the traditional manner,
  7689.             iterating so  long as  the while condition is true.  This
  7690.             example keeps  popping up  through the  various levels of
  7691.             parent directories  until it  reaches the root.  fullpath
  7692.             is one  of the  built-in procedures; it return the fully-
  7693.             qualified pathname of its argument.  Notice that fullpath
  7694.             is invoked  in three  different ways:  on line 413, as if
  7695.             it were  a command, on 414 in more conventional procedure
  7696.             syntax and  on 415,  where it's  substituted in  as if it
  7697.             were a variable.
  7698.  
  7699.                  413 D% fullpath .
  7700.                  d:\doug\samples
  7701.                  414 D% while (fullpath(".") !~ "[a-zA-Z]:\")
  7702.                  415 D?    echo $fullpath(".")
  7703.                  416 D?    cd ..
  7704.                  417 D? end
  7705.                  d:\doug\samples
  7706.                  d:\doug
  7707.                  418 D% cd
  7708.                  d:\
  7709.  
  7710.  
  7711.  
  7712.             Repeat Statement
  7713.  
  7714.                The repeat  statement has  two forms.   In  the  short
  7715.             form, a  numeric constant  (not an  expression) specifies
  7716.             the number of times to execute the statement following on
  7717.             the same line.
  7718.  
  7719.                  419 D% repeat 4 echo do this again
  7720.                  do this again
  7721.                  do this again
  7722.                  do this again
  7723.                  do this again
  7724.  
  7725.                In  the   long  form,   repeat   provides   the   more
  7726.             conventional repeat  structure, iterating until some exit
  7727.             condition satisfied.
  7728.  
  7729.                  420 D% calc i = 1
  7730.                  1
  7731.                  421 D% repeat
  7732.                  422 D?    calc i++
  7733.  
  7734.  
  7735.  
  7736.                                      Page 118
  7737.  
  7738.                                                        Programming Constructs
  7739.  
  7740.  
  7741.                  423 D? until (i > 5)
  7742.                  1
  7743.                  2
  7744.                  3
  7745.                  4
  7746.                  5
  7747.  
  7748.  
  7749.  
  7750.             Procedures
  7751.  
  7752.                Procedures, as  in  any  high-level  language,  are  a
  7753.             convenient way to package together a series of statements
  7754.             as a  more convenient  operation.   Once you've defined a
  7755.             procedure, you  can invoke  it simply as if it were a new
  7756.             command.
  7757.  
  7758.                  424 D% proc hello()
  7759.                  425 D?    echo hello world
  7760.                  426 D? end
  7761.                  427 D% hello
  7762.                  hello world
  7763.  
  7764.                The proc  statement can  also  be  used  to  ask  what
  7765.             procedures  are  already  defined  or  what  arguments  a
  7766.             particular procedure takes:
  7767.  
  7768.                  428 D% proc hello
  7769.                  hello        ( )
  7770.                  429 D% proc | mi
  7771.                  abs          ( x )
  7772.                  acos         ( x )
  7773.                  asin         ( x )
  7774.                  :
  7775.                  :
  7776.                  samepath     ( a, b )
  7777.                  sin          ( x )
  7778.                  sinh         ( x )
  7779.                  --- more --- (Press H for Help)
  7780.  
  7781.                You can  explicitly discard  a definition with unproc;
  7782.             otherwise the  shell remembers  any procedure you tell it
  7783.             until you exit the shell or give it a new definition.
  7784.  
  7785.                  430 D% unproc hello
  7786.                  431 D% hello
  7787.                  csh:  Couldn't find an executable file named
  7788.                  'hello'.
  7789.  
  7790.                When you  give the  shell a  procedure definition, the
  7791.             shell compiles  it into an internal form so that the next
  7792.             time you  refer to  it, it'll save the reparsing time and
  7793.             run much  faster.   As an  example, unproc   the  whereis
  7794.             procedure to  make the  shell reload  the definition from
  7795.  
  7796.  
  7797.  
  7798.                                      Page 119
  7799.  
  7800.      Programming Constructs
  7801.  
  7802.  
  7803.             the .csh  file and  see what  that does  to the execution
  7804.             time:
  7805.  
  7806.                  432 D% unproc whereis
  7807.                  433 D% time whereis ls
  7808.                  f:\os2\bin\ls.exe
  7809.                  0:00:02.15
  7810.                  434 D% !!
  7811.                  time whereis ls
  7812.                  f:\os2\bin\ls.exe
  7813.                  0:00:01.28
  7814.  
  7815.                The namespace  for procedures  is shared among all the
  7816.             threads:   if one  thread creates  a  new  procedure,  it
  7817.             becomes usable immediately by all the other threads.
  7818.  
  7819.  
  7820.  
  7821.             Arguments
  7822.  
  7823.                You can  write a  procedure so  it expects  arguments,
  7824.             just as  you would  in any  other  high  level  language.
  7825.             Argument names  are somewhat like local variables:  their
  7826.             initial values  are set  at entry  to a procedure, hiding
  7827.             any previous  definition; they  go away  as soon you exit
  7828.             the procedure  code.    Here's  a  simple  example  which
  7829.             compares the timestamps on two files.
  7830.  
  7831.                  435 D% proc comparedates(a, b)
  7832.                  436 D?    if (`newer $a $b`) then
  7833.                  437 D?       echo $a is newer than $b
  7834.                  438 D?    else
  7835.                  439 D?       if (samepath(a, b)) then
  7836.                  440 D?          echo $a and $b are the same file!
  7837.                  441 D?       else
  7838.                  442 D?          echo $a is older than $b
  7839.                  443 D?       end
  7840.                  444 D?    end
  7841.                  445 D? end
  7842.                  446 D% comparedates `whereis more`
  7843.                  c:\os2\bin\more.exe is newer than
  7844.                  c:\os2\cmds\more.com
  7845.                  447 D% _
  7846.  
  7847.                When you  pass arguments to a procedure on the command
  7848.             line, the  individual argument  words are paired up, one-
  7849.             by-one, with  the argument  names you gave.  If the shell
  7850.             runs out  of names  before it runs out of words, the last
  7851.             named argument gets all the remaining words:
  7852.  
  7853.                  447 D% proc xx(a, b)
  7854.                  448 D?   echo $#a $a
  7855.                  449 D?   echo $#b $b
  7856.                  450 D? end
  7857.  
  7858.  
  7859.  
  7860.                                      Page 120
  7861.  
  7862.                                                        Programming Constructs
  7863.  
  7864.  
  7865.                  451 D% xx now is the time
  7866.                  1 now
  7867.                  3 is the time
  7868.  
  7869.             If you  pass arguments  to a  procedure that doesn't take
  7870.             any, they're evaluated but quietly ignored.
  7871.  
  7872.                  If a  procedure does take an argument, it always get
  7873.             some value, even if it's zero words long.  So if you want
  7874.             to know  if you got passed a value, just count the number
  7875.             of words:
  7876.  
  7877.                  452 D% proc xx(a)
  7878.                  453 D?    echo $#a ">>$a<<"
  7879.                  454 D?    if (a == "") echo null argument!
  7880.                  455 D? end
  7881.                  456 D% xx
  7882.                  0 >><<
  7883.                  null argument!
  7884.  
  7885.                In a  more serious  vein, here's  a  simple  procedure
  7886.             definition  I   use  all  the  time  (I  have  it  in  my
  7887.             startup.csh file)  to implement  a real  quick and  dirty
  7888.             (but very easy to use!) personal phone index:
  7889.  
  7890.                  457 D% proc ppi(name)
  7891.                  458 D?    grep -i "$name" h:\phone
  7892.                  459 D? end
  7893.                  460 D% ppi hamilton
  7894.                  Hamilton Laboratories  508-358-5715  Fax: 508-358-
  7895.                  1113
  7896.  
  7897.             As you  add lines to your \phone file, you merely add any
  7898.             interesting search phrases or other tidbits onto the same
  7899.             line with  the person's  name.  Totally free format.  Add
  7900.             anything you  like and  search on  anything you  like and
  7901.             it's fast.
  7902.  
  7903.  
  7904.  
  7905.              Return Values
  7906.  
  7907.                Procedures are  also important  in expressions,  where
  7908.             it's generally  useful  to  think  of  the  procedure  as
  7909.             returning  a  value,  just  as  it  might  in  any  other
  7910.             language.   The type  and value  of what  you  choose  to
  7911.             return  is  arbitrary.    Here's  a  purely  mathematical
  7912.             example from finance.csh in the samples directory:
  7913.  
  7914.                  461 D% proc FV_PresentAmount(i, n)
  7915.                  462 D?    # Calculate the multiplier to convert $1
  7916.                  now to a
  7917.                  463 D?    #    future value, given interest rate i
  7918.                  464 D?     return 1/(1 + i/100)**n
  7919.  
  7920.  
  7921.  
  7922.                                      Page 121
  7923.  
  7924.      Programming Constructs
  7925.  
  7926.  
  7927.                  465 D? end
  7928.                  466 D% # Calculate the future value of $500 invested
  7929.                  467 D% # for 10 years at 8% interest.
  7930.                  468 D% calc 500*FV_PresentAmount(8, 10)
  7931.                  1079.462499
  7932.  
  7933.                If you  call a procedure that returns a value as if it
  7934.             were a command, whatever it returns is printed:
  7935.  
  7936.                  469 D% FV_PresentAmount 8 10
  7937.                  2.158925
  7938.  
  7939.  
  7940.  
  7941.             Recursion
  7942.  
  7943.                A procedure  can call other procedures or even itself.
  7944.             When a  procedure calls  itself, it's  called  recursion.
  7945.             Typical uses  of recursion are in cases where the problem
  7946.             itself is  recursive, or  self-replicating.  For example,
  7947.             here's a procedure to walk down two directory trees A and
  7948.             B that  are thought to be related and list any non-hidden
  7949.             files in  A that  are not in B.  (If you set nonohidden =
  7950.             1, it'll compare hidden files also.)
  7951.  
  7952.  
  7953.  
  7954.  
  7955.  
  7956.  
  7957.  
  7958.  
  7959.  
  7960.  
  7961.  
  7962.  
  7963.  
  7964.  
  7965.  
  7966.  
  7967.  
  7968.  
  7969.  
  7970.  
  7971.  
  7972.  
  7973.  
  7974.  
  7975.  
  7976.  
  7977.  
  7978.  
  7979.  
  7980.  
  7981.  
  7982.  
  7983.  
  7984.                                      Page 122
  7985.  
  7986.                                                        Programming Constructs
  7987.  
  7988.  
  7989.                  470 D% proc comparetrees(a, b)
  7990.                  441 D?    local i, f
  7991.                  472 D?    foreach i ($a\*)
  7992.                  473 D?       @ f = $i:t
  7993.                  474 D?       if (! -e $b\$f) then
  7994.                  475 D?          echo $b\$f is missing
  7995.                  476 D?       else
  7996.                  477 D?          if (-d $i) comparetrees $i $b\$f
  7997.                  478 D?       end
  7998.                  479 D?    end
  7999.                  480 D? end
  8000.                  481 D% comparetrees c:\src\projectx a:\src
  8001.  
  8002.                Notice that  i and f were declared as local variables.
  8003.             If the  variables were simply set variables, one instance
  8004.             of them  would be  shared by all the levels of recursion.
  8005.             In this particular example, that would still have worked,
  8006.             but only  because each  level calls  the next  only after
  8007.             anything involving f or i has been evaluated; it wouldn't
  8008.             matter if  f or  i was trampled by the next call.  Here's
  8009.             an example  where obviously  that would  not be  true:  a
  8010.             clumsy  attempt   at  a  ``post-order''  traversal  of  a
  8011.             directory tree:
  8012.  
  8013.                  482 D% proc traverse(a)   # Don't do it this way
  8014.                  483 D?    foreach i ($a\*)
  8015.                  484 D?      if (-d $i) traverse $i
  8016.                  485 D?      echo $i
  8017.                  486 D?    end
  8018.                  487 D? end
  8019.                  488 D% traverse . | more
  8020.  
  8021.                If you  carefully examine the output of this traverse,
  8022.             you'll see that subdirectories don't get listed properly:
  8023.             instead of  being listed by themselves, the name of their
  8024.             last child is listed twice.  For a correct result, try it
  8025.             again with  i defined  as a  local variable.    (Use  the
  8026.             <PageUp> key  to help you quickly re-enter the lines that
  8027.             stay the same.)
  8028.  
  8029.  
  8030.  
  8031.             Calling a Procedure
  8032.  
  8033.                As you  may have spotted, there are two ways to invoke
  8034.             a  procedure.     Sometimes,  the  arguments  are  inside
  8035.             parentheses, separated  by commas,  and sometimes they're
  8036.             not.  What's the difference?
  8037.  
  8038.                The difference is whether the context is an expression
  8039.             or a  command.   As discussed  when we  first  introduced
  8040.             expressions, the  shell always begins to parse statements
  8041.             by first  breaking them  up into  words.  That's fine for
  8042.             normal commands,  e.g., running an external utility.  And
  8043.  
  8044.  
  8045.  
  8046.                                      Page 123
  8047.  
  8048.      Programming Constructs
  8049.  
  8050.  
  8051.             it works  also when  you want to use a procedure as if it
  8052.             were a  command, just  typing the  name of  the procedure
  8053.             followed by  a list  of arguments  separated  by  spaces,
  8054.             e.g.,
  8055.  
  8056.                  489 D% proc power(a, b)
  8057.                  490 D?    return a**b
  8058.                  491 D? end
  8059.                  492 D% power 2 3
  8060.                  8
  8061.                  493 D% _
  8062.  
  8063.                But this style of parsing wouldn't be very suitable in
  8064.             those instances  where the  point is  to do  some kind of
  8065.             calculation or  expression evaluation.  So when the shell
  8066.             encounters something  that normally  takes an expression,
  8067.             e.g., following  the calc  keyword, or inside the test in
  8068.             an if  statement, it  shifts  to  a  different  style  of
  8069.             parsing, further  breaking up  the words  into tokens, so
  8070.             that ``*'' isn't misunderstood as a wildcard, so we don't
  8071.             need to  type spaces  around all the operators, so we can
  8072.             type variable  names without  having to  put a  ``$''  in
  8073.             front of  them and  so on.   All  of this  is so that the
  8074.             rules for  typing an expression can bear some resemblance
  8075.             to those  followed by other programming languages like C,
  8076.             Fortran, Pascal, etc.
  8077.  
  8078.                When we  call a  procedure from  within an expression,
  8079.             all these  same arguments still apply.  We want it to act
  8080.             pretty much like any other high level languages.  We want
  8081.             to be  able to pass it arbitrarily complex expressions as
  8082.             arguments.   We want  to be  able to  take the  value  it
  8083.             returns and  use that  value as  a term  in  still  other
  8084.             expressions.
  8085.  
  8086.                So there's  a real  problem:  to call a procedure from
  8087.             within  an  expression  and  pass  other  expressions  as
  8088.             arguments, we  need a way of separating one argument from
  8089.             the next (obviously, it can't be just a space as it would
  8090.             be when  the procedure  is used  as if it were a command)
  8091.             and for  separating the  whole  procedure  call  and  its
  8092.             arguments from  the rest  of the  expression.  That's why
  8093.             the common  high-level language  convention of separating
  8094.             arguments by  commas and  putting parentheses  around the
  8095.             whole list is used.  Here's an example of what that looks
  8096.             like:
  8097.  
  8098.                  493 D% calc 5.5 + power(2, 3)*9
  8099.                  77.500000
  8100.  
  8101.                If  you  try  using  a  procedure  as  a  command  but
  8102.             accidentally type  the argument  list  with  parenthesis,
  8103.             it's an error:
  8104.  
  8105.  
  8106.  
  8107.  
  8108.                                      Page 124
  8109.  
  8110.                                                        Programming Constructs
  8111.  
  8112.  
  8113.                  494 D% power(2, 3)
  8114.                  csh(line 490):  Couldn't evaluate expression
  8115.                  operands as numeric as required by the expression
  8116.                  operator.
  8117.                  > in power( "(", "2,", "3", ")" ) defined at line
  8118.                  489
  8119.                  < called from line 494
  8120.  
  8121.             The reason  this is  an error  is because, since this was
  8122.             typed as  a command,  the shell  took the words following
  8123.             the word  power as  literal arguments.   It couldn't tell
  8124.             you meant  this as  an expression.   Let's  redefine that
  8125.             procedure, putting  some echo  statements in  there so we
  8126.             can see what happened:
  8127.  
  8128.                  495 D% proc power(a, b)
  8129.                  496 D?   echo a is $a
  8130.                  497 D?   echo b is $b
  8131.                  498 D?   return a**b
  8132.                  499 D? end
  8133.                  500 D% power(2, 3)
  8134.                  a is (
  8135.                  b is 2, 3 )
  8136.                  csh(line 498):  Couldn't evaluate expression
  8137.                  operands as numeric as required by the expression
  8138.                  operator.
  8139.                  > in power( "(", "2,", "3", ")" ) defined at line
  8140.                  487
  8141.                  < called from line 500
  8142.  
  8143.             As  you  can  see,  the  expression  ``a**b''  failed  to
  8144.             evaluate properly because a was set to the first argument
  8145.             word, ``('',  and b  was set to a string concatenation of
  8146.             all the rest of the words.  Neither was a number.
  8147.  
  8148.                If you  want to  call a  procedure and  substitute the
  8149.             value back onto the command line even when the context is
  8150.             not an  expression, it  can be done, however.  One way is
  8151.             with command substitution:
  8152.  
  8153.                  501 D% echo `power 2 3`
  8154.                  a is 2 b is 3 8
  8155.  
  8156.                This is  a bit  expensive, though,  because the  shell
  8157.             will have  to create  a  new  thread  to  run  the  power
  8158.             procedure and  set up  a pipe to read the result.  And as
  8159.             you see,  if the  procedure also writes to stdout, you'll
  8160.             pick up that text also, probably unintentially.  Another,
  8161.             better way,  is to  use a  dollar sign  to introduce  the
  8162.             substitution just as if it was a variable substitution:
  8163.  
  8164.                  502 D% echo $power(2, 3)
  8165.                  a is 2
  8166.  
  8167.  
  8168.  
  8169.  
  8170.                                      Page 125
  8171.  
  8172.      Programming Constructs
  8173.  
  8174.  
  8175.                  b is 3
  8176.                  8
  8177.  
  8178.             Notice that  when use  the  dollar  sign-style  procedure
  8179.             reference, the  rest of the syntax is as if the procedure
  8180.             had been called from within an expression.  The arguments
  8181.             do need  to be  within parenthesis and they do need to be
  8182.             separated by  commas.  The reason is just the same one as
  8183.             for why  a procedure call in an expression has to be done
  8184.             this way:   without the parentheses, there'd be no way to
  8185.             tell where  the arguments  ended.  A nice benefit is that
  8186.             in the  argument list,  we get to use the full expression
  8187.             grammar:
  8188.  
  8189.                  503 D% echo $power(2, 3*sin(1/2))
  8190.                  a is 2
  8191.                  b is 1.438277
  8192.                  2.709970
  8193.  
  8194.  
  8195.  
  8196.             Shell Scripts
  8197.  
  8198.                Scripts are  a final  way of  bundling up  a series of
  8199.             statements to  be called  up and  executed  as  a  single
  8200.             command.   To create  a script, create a file with a .csh
  8201.             extension:
  8202.  
  8203.                  504 D% cat >trythis.csh
  8204.                  echo hello from trythis
  8205.                  ^Z
  8206.                  505 D% trythis
  8207.                  hello from trythis
  8208.  
  8209.                When you  tell the  shell to  run a  script, it  first
  8210.             creates a  new thread  to run  it.    This  is  partly  a
  8211.             holdover from original UNIX language definition, partly a
  8212.             response to  a provision  in OS/2 and NT for threads, but
  8213.             not a  fork mechanism and partly due to a genuine need to
  8214.             inexpensively separate  some of  the script's environment
  8215.             from that  of its caller.  (The next chapter has a longer
  8216.             discussion of threads.)
  8217.  
  8218.  
  8219.  
  8220.             Shell Script Arguments
  8221.  
  8222.                Arguments to  a shell  script are  passed to it as the
  8223.             argv variable.   argv  will be  a list  of any words that
  8224.             appeared on  the command  line following  the name of the
  8225.             shell script.   (You can access the name of the script as
  8226.             the scriptname  variable.)   You can access argv like any
  8227.             other variable:
  8228.  
  8229.  
  8230.  
  8231.  
  8232.                                      Page 126
  8233.  
  8234.                                                        Programming Constructs
  8235.  
  8236.  
  8237.                  506 D% cat >tryargv.csh
  8238.                  echo $#argv $argv
  8239.                  ^Z
  8240.                  507 D% tryargv hello how are you
  8241.                  4 hello how are you
  8242.  
  8243.                There  are  also  some  shorthand  forms  for  getting
  8244.             individual words  of argv.   $0 through $9 is the same as
  8245.             $argv[0] through  $argv[9].   (Remember that  unless  you
  8246.             have nullwords set, subscripting errors will be caught.)
  8247.  
  8248.  
  8249.  
  8250.             ignorestatus
  8251.  
  8252.                If  you   write  a   script  with  serially  connected
  8253.             statements the  only thing  that would cause the shell to
  8254.             quit before  it gets  to the  end would  be  an  explicit
  8255.             failure:   an application  name that couldn't be found, a
  8256.             child process  that terminated  with a  segment fault, or
  8257.             something else  of an equally serious nature.  Often in a
  8258.             script, that's  not what  you want:   you've  written the
  8259.             script with the expectation that everything will work (as
  8260.             you planned)  from one step to the next.  If something is
  8261.             wrong, you'd like the script to quit as soon as possible,
  8262.             before any damage is done.
  8263.  
  8264.                The way  you do  this is  by setting ignorestatus = 0,
  8265.             which means  you do  not want  to ignore the status codes
  8266.             coming back  to this thread from its children.  Here's an
  8267.             example in the main thread:
  8268.  
  8269.                  508 D% set ignorestatus = 0
  8270.                  509 D% rcode 10
  8271.                  10
  8272.                  csh:  The child process running 'rcode' exited with
  8273.                  a non-zero status = 10.
  8274.  
  8275.             In the  main thread,  the shell  will keep  on going  and
  8276.             prompt for  the next command because interactively that's
  8277.             most sensible.   The  shell  knows  to  do  this  because
  8278.             ignoreerrors =  1.   But in  a script,  errors cause  the
  8279.             shell to quit:
  8280.  
  8281.  
  8282.  
  8283.  
  8284.  
  8285.  
  8286.  
  8287.  
  8288.  
  8289.  
  8290.  
  8291.  
  8292.  
  8293.  
  8294.                                      Page 127
  8295.  
  8296.      Programming Constructs
  8297.  
  8298.  
  8299.                  510 D% cat >trythis.csh
  8300.                  calc ignoreerrors
  8301.                  set ignorestatus = 0
  8302.                  rcode 10
  8303.                  echo does^'t print
  8304.                  ^Z
  8305.                  511 D% trythis
  8306.                  0
  8307.                  10
  8308.                  csh(d:\doug\trythis.csh:line 3): The child process
  8309.                  running 'rcode' exited with a non-zero status = 10.
  8310.                  > in d:\doug\trythis.csh
  8311.                  < called from line 511
  8312.                  csh:  The csh script file
  8313.                  'd:\doug\samples\trythis.csh' exited with a non-zero
  8314.                  status = 10.
  8315.  
  8316.             Notice that  in this  case we  got two messages, one from
  8317.             the threads  executing the  script and  one from the main
  8318.             thread, reporting what the script returned.  Let's return
  8319.             to the normal mode of ignoring status:
  8320.  
  8321.                  512 D% set ignorestatus = 1
  8322.  
  8323.  
  8324.  
  8325.             source statement
  8326.  
  8327.                The examples  so  far  have  shown  how  a  script  is
  8328.             normally run  somewhat isolated in a separate thread.  It
  8329.             is also  possible to  run a script in your current thread
  8330.             using the source statement.  You might want to do this if
  8331.             you wanted  to the script to change your current thread's
  8332.             private variables  or its  current directories  or  disk.
  8333.             Here's an example to showing how a sourced script runs in
  8334.             the same thread:
  8335.  
  8336.                  513 D% cat >trythis.csh
  8337.                  echo argv = $argv, threadid = $threadid
  8338.                  ^Z
  8339.                  514 D% echo $threadid
  8340.                  6
  8341.                  515 D% trythis hello world
  8342.                  argv = hello world, threadid = 7
  8343.                  516 D% source trythis hello world
  8344.                  argv = hello world, threadid = 6
  8345.                  518 D% _
  8346.  
  8347.             Notice how the argv argument vector is set up the same in
  8348.             either case.   Also,  notice that  the  statement  number
  8349.             skipped by  one.  When you source a script, the effect is
  8350.             precisely as  if you typed those lines in directly to the
  8351.             shell.   The lines  read by  source are even entered into
  8352.             the history list:
  8353.  
  8354.  
  8355.  
  8356.                                      Page 128
  8357.  
  8358.                                                        Programming Constructs
  8359.  
  8360.  
  8361.                  518 D% h 5
  8362.                      514  echo $threadid
  8363.                      515  trythis hello world
  8364.                      516  source trythis hello world
  8365.                      517  echo argv = $argv, threadid = $threadid
  8366.                      518  h 5
  8367.  
  8368.  
  8369.  
  8370.             Caution:  Labels and Gotos
  8371.  
  8372.                We haven't  mentioned labels  and  gotos  yet  but  it
  8373.             probably isn't  a surprise  that the C shell allows them.
  8374.             Indeed:
  8375.  
  8376.                  519 D% cat >trythis.csh
  8377.                  goto next
  8378.                  echo this does not print
  8379.                  next: echo this prints
  8380.                  ^Z
  8381.                  520 D% trythis
  8382.                  this prints
  8383.  
  8384.                If you  want to  use gotos  to labels,  you should  be
  8385.             aware that forward references can be little trickier than
  8386.             a more  conventional compiled  language.    The  C  shell
  8387.             allows you  to redefine a label anytime you like.  But if
  8388.             you type  a goto that refers to previously defined label,
  8389.             the shell  has no  way of  knowing that  you intend it to
  8390.             redefine it  up ahead.   You  can keep  running the  last
  8391.             example over  and over  this way  with exactly  the  same
  8392.             result:   because a  new thread is started each time with
  8393.             no prior definition of next, the shell knows it must be a
  8394.             forward reference.   But  imagine how repeatedly sourcing
  8395.             this script would fail in an infinite loop:
  8396.  
  8397.                  % source trythis
  8398.                  this prints
  8399.                  % source trythis
  8400.                  this prints
  8401.                  this prints
  8402.                  this prints
  8403.                  this prints
  8404.                  this prints
  8405.                  :
  8406.                  
  8407.  
  8408.             (Beware of  actually  trying  this:    you  may  find  it
  8409.             difficult to interrupt out of it.)
  8410.  
  8411.                The reason  sourcing the  script a  second time  turns
  8412.             into an  infinite loop  is that the label next is already
  8413.             defined after  the first  run.  The second time, when the
  8414.  
  8415.  
  8416.  
  8417.  
  8418.                                      Page 129
  8419.  
  8420.      Programming Constructs
  8421.  
  8422.  
  8423.             goto is read from the script, the history list would look
  8424.             something like this:
  8425.  
  8426.                  source trythis
  8427.                  goto next
  8428.                  echo does not print
  8429.                  next: echo this prints
  8430.                  source trythis
  8431.                  goto next
  8432.  
  8433.             What particularly gets the shell into a muddle is the way
  8434.             this recurses  indefinitely: each  time through the loop,
  8435.             it  recurses   through  an  another  level  of  sourcing.
  8436.             Ultimately, it  runs out of stack space and fails.   This
  8437.             is not a nice way to treat the shell!
  8438.  
  8439.                In general,  it's  hard  to  recommend  gotos  in  any
  8440.             programming language  nowadays; in a script you intend to
  8441.             run using source, they can be particularly nasty.
  8442.  
  8443.                The shell does automatically age labels and throw them
  8444.             away after  a while  even if they haven't been redefined.
  8445.             When it  discards a  label, it also discards any compiled
  8446.             statements it's  been holding  onto that  could have been
  8447.             executed only  by a goto to that label.  The cutoff point
  8448.             where the  shell begins  to discard  labels is set by the
  8449.             gotowindow variable.   Let's now clean up after ourselves
  8450.             and move along:
  8451.  
  8452.                  521 D% rm trythis.csh
  8453.  
  8454.  
  8455.  
  8456.             Interrupts
  8457.  
  8458.                Normally,  when   you  type   ^C,  you  interrupt  the
  8459.             foreground activity.   But  what if you were in the midst
  8460.             of a complex script and needed to do some kind of cleanup
  8461.             before you exited?  What if you wanted to be sure you had
  8462.             a chance  to delete  any temporary  files you  might have
  8463.             littered around?
  8464.  
  8465.                The solution is the onintr statement, which allows you
  8466.             to define  the action  to be  taken when  an interrupt is
  8467.             received.  It causes whatever's running to be interrupted
  8468.             all the  way back  up to  the block  in which  the onintr
  8469.             routine was  defined and  for the interrupt routine to be
  8470.             run in  that  current  thread.    Within  that  interrupt
  8471.             routine,  you   could,  for   example,  remove  all  your
  8472.             temporary files  and goto the end of the script or return
  8473.             a special  value from  a procedure or whatever else might
  8474.             be appropriate.
  8475.  
  8476.  
  8477.  
  8478.  
  8479.  
  8480.                                      Page 130
  8481.  
  8482.                                                        Programming Constructs
  8483.  
  8484.  
  8485.                  522 D% onintr echo hello
  8486.                  523 D% for i = 1 to 5 do
  8487.                  524 D?    echo $i
  8488.                  525 D?    sleep 1
  8489.                  526 D? end
  8490.                  1
  8491.                  ^C
  8492.                  hello
  8493.  
  8494.                Here's another  example, returning  from a  procedure.
  8495.             Note how  the value  returned (and  printed) is  the  one
  8496.             produced by the onintr statement.
  8497.  
  8498.                  527 D% proc foobar()
  8499.                  528 D?    onintr return 5
  8500.                  529 D?    for i = 1 to 5 do
  8501.                  530 D?        echo $i
  8502.                  531 D?        sleep 1
  8503.                  532 D?    end
  8504.                  533 D? return 2
  8505.                  534 D? end
  8506.                  535 D% foobar
  8507.                  1
  8508.                  ^C
  8509.                  5
  8510.  
  8511.                When execution  leaves the block in which an onintr is
  8512.             defined, the previous onintr (if any) again takes effect.
  8513.             Note that  a null  onintr  routine  does  not  mean  that
  8514.             interrupts are  ignored,  merely  that  after  processing
  8515.             bubbles back  up to  the  level  where  that  onintr  was
  8516.             defined, that  it will  continue with the next statement.
  8517.             Notice how, in this example, when the ^C is received when
  8518.             obviously execution  is stuck in the infinite loop inside
  8519.             bar, that the ``onintr goto xx'' causes a branch to xx in
  8520.             the same  block in  which the onintr was defined, not the
  8521.             xx in  the block  where execution  was going  on.   Also,
  8522.             notice that  once both procedures have been exited, we're
  8523.             back  to  the  same  onintr  routine  we  defined  a  few
  8524.             statements earlier.
  8525.  
  8526.                  536 D% proc foo()
  8527.                  537 D?    onintr goto xx
  8528.                  538 D?    bar
  8529.                  539 D?   xx:  echo this is foo
  8530.                  540 D? end
  8531.                  541 D% proc bar()
  8532.                  542 D?    while (1)   # Deliberately infinite loop
  8533.                  543 D?    end
  8534.                  544 D?   xx:  echo this is bar
  8535.                  545 D? end
  8536.                  546 D% foo
  8537.                  ^C
  8538.                  this is foo
  8539.  
  8540.  
  8541.  
  8542.                                      Page 131
  8543.  
  8544.      Programming Constructs
  8545.  
  8546.  
  8547.                  547 D% ^C
  8548.                  hello
  8549.                  547 D% _
  8550.  
  8551.  
  8552.  
  8553.             Masking Interrupts
  8554.  
  8555.                In  cases   where  you'd   like  to  simply  turn  off
  8556.             interrupts or  defer processing  them,  use  the  irqmask
  8557.             variable.   By default, it's set to 0, meaning interrupts
  8558.             will be  accepted immediately.   Setting  it to  1  means
  8559.             interrupts will  be deferred  until the  mask is  cleared
  8560.             again.   Setting it to 2 means interrupts will be totally
  8561.             ignored.
  8562.  
  8563.                irqmask is  a per-thread variable, meaning each thread
  8564.             can  independently   decide  how   it  will   respond  to
  8565.             interrupts.   Each new  thread  always  starts  out  with
  8566.             irqmask = 0 (interrupts enabled).
  8567.  
  8568.  
  8569.  
  8570.  
  8571.  
  8572.  
  8573.  
  8574.  
  8575.  
  8576.  
  8577.  
  8578.  
  8579.  
  8580.  
  8581.  
  8582.  
  8583.  
  8584.  
  8585.  
  8586.  
  8587.  
  8588.  
  8589.  
  8590.  
  8591.  
  8592.  
  8593.  
  8594.  
  8595.  
  8596.  
  8597.  
  8598.  
  8599.  
  8600.  
  8601.  
  8602.  
  8603.  
  8604.                                      Page 132
  8605.  
  8606.                                                        Programming Constructs
  8607.  
  8608.  
  8609.             
  8610.  
  8611.  
  8612.  
  8613.  
  8614.  
  8615.  
  8616.  
  8617.  
  8618.  
  8619.  
  8620.  
  8621.  
  8622.  
  8623.  
  8624.  
  8625.  
  8626.  
  8627.  
  8628.  
  8629.  
  8630.  
  8631.  
  8632.  
  8633.  
  8634.  
  8635.  
  8636.  
  8637.  
  8638.  
  8639.  
  8640.  
  8641.  
  8642.  
  8643.  
  8644.  
  8645.  
  8646.  
  8647.  
  8648.  
  8649.  
  8650.  
  8651.  
  8652.  
  8653.  
  8654.  
  8655.  
  8656.  
  8657.  
  8658.  
  8659.  
  8660.  
  8661.  
  8662.  
  8663.  
  8664.  
  8665.  
  8666.                                      Page 133
  8667.  
  8668.      Scheduling
  8669.  
  8670.  
  8671.             
  8672.  
  8673.  
  8674.                                    Scheduling
  8675.  
  8676.  
  8677.  
  8678.  
  8679.             Foreground Activities
  8680.  
  8681.                Whenever you  type any  command,  the  shell's  normal
  8682.             behavior is  to start  up that child activity and then go
  8683.             to  sleep  waiting  for  it  to  complete.    This  is  a
  8684.             foreground activity.   If  you start  something and  then
  8685.             decide you  want to  stop it, type Control-C, which wakes
  8686.             up the  shell  and  causes  it  to  stop  the  foreground
  8687.             activities.
  8688.  
  8689.                Under OS/2,  Hamilton C shell can tell the difference+
  8690.             between    full-screen,    text-windowable    and    full
  8691.             Presentation Manager applications and properly spawns new
  8692.             screen groups  for applications  that can't  run  in  the
  8693.             shell's window.   For  example, typing  the name  of  the
  8694.             Presentation Manager control panel:
  8695.  
  8696.                  547 D% pmcpl
  8697.  
  8698.             will (or  at least,  should) cause  the control  panel to
  8699.             appear in a new window.
  8700.  
  8701.                Similarly, under Windows NT, if you type the name of a
  8702.             graphical application,  the C  shell will  recognize that
  8703.             based on an actual examination of the file itself.
  8704.  
  8705.                Under both  OS/2 and  Windows NT,  when you  start  an
  8706.             application that  needs a  new window,  the  shell  comes
  8707.             right back for the next command.
  8708.  
  8709.                Also, if  the child  is a  a graphical application and
  8710.             stdout or  stderr is tied to the console window where the
  8711.             C shell's  running, the  C  shell  recognizes  that  that
  8712.             handle won't be inheritable by the child and instead will
  8713.             ____________________
  8714.             + Actually, under  OS/2, the  shell depends  on the  .exe
  8715.               file being  properly marked with  the application type.
  8716.               Unfortunately, not   all  developers yet know about and
  8717.               obey this rule.  For example, in some releases of OS/2,
  8718.               even IBM  forgot to  mark some applications such as the
  8719.               control panel.   Unmarked applications are, by default,
  8720.               started full-screen;  a PM  application that's  started
  8721.               this way  dies immediately.  If you spot this behavior,
  8722.               you should  mark the  offending application  using  the
  8723.               markexe  utility.     (Type  ``markexe  -h''  for  more
  8724.               information.)
  8725.  
  8726.  
  8727.  
  8728.                                      Page 134
  8729.  
  8730.                                                                    Scheduling
  8731.  
  8732.  
  8733.             create a pipe.  It'll give the write end to the child and
  8734.             create a  background  thread  in  the  C  shell  to  read
  8735.             anything coming  back over  the pipe  from the  child and
  8736.             copy it  to the console window.  This means that with the
  8737.             C shell, you can still use ordinary printf's in a OS/2 PM
  8738.             or NT graphical application and not lose any output.
  8739.  
  8740.  
  8741.  
  8742.             Background Activities
  8743.  
  8744.                If you  want to  run something  but don't want to wait
  8745.             for it complete, just type an ampersand at the end of the
  8746.             statement:
  8747.  
  8748.                  548 D% wc hello.c >linecnt &
  8749.                  1
  8750.                  549 D% _
  8751.  
  8752.             This creates  a child  process to  run word  count in the
  8753.             background, with  its output  directed to  a file.    The
  8754.             ``1'' message means that a new background job (job 1) has
  8755.             been spawned to process the command while you continue to
  8756.             work.   The job  starts as  a new thread.  If, as in this
  8757.             case, a  separate process  is needed,  that  thread  will
  8758.             create it  with a  DosExecPgm call to the OS/2 kernel (or
  8759.             CreateProcess  call   to  the   Windows  NT   kernel,  as
  8760.             appropriate), then  exit.   Each new  thread, process  or
  8761.             screen group spawned by a background job will inherit its
  8762.             parent's job  number.  Every time a new background job is
  8763.             created, the job number is incremented.
  8764.  
  8765.                The use  of i/o  redirection  in  combination  with  a
  8766.             background activity  is not  accidental.    If  it's  not
  8767.             redirected, it  goes to  your terminal,  intermixing with
  8768.             the output  of any  foreground activities.  Occasionally,
  8769.             that might be exactly what you want.  For example, here's
  8770.             a timer to wake you up in 5 minutes (300 seconds):
  8771.  
  8772.                  549 D% (sleep 300; echo ^aWake Up, Sleepyhead.) &
  8773.                  2
  8774.                  :
  8775.                  :
  8776.                  Beep
  8777.                  Wake Up, Sleepyhead.
  8778.  
  8779.                The ampersand  works consistently for things that need
  8780.             a new window:
  8781.  
  8782.                  550 D% pmcpl &
  8783.                  3
  8784.                  551 D% _
  8785.  
  8786.  
  8787.  
  8788.  
  8789.  
  8790.                                      Page 135
  8791.  
  8792.      Scheduling
  8793.  
  8794.  
  8795.             A new  job starts  up and announces itself, then realizes
  8796.             that the  control panel  has to  be  run  in  a  separate
  8797.             session.  Once it's started the child session, the thread
  8798.             exits and  its children  are adopted by its parent thread
  8799.             and child is left running as job 3.
  8800.  
  8801.                Under both  OS/2 and Windows NT, background activities
  8802.             are,  in  a  sense,  detached:    typing  Ctrl-C  doesn't
  8803.             interrupt  them   (unless  they   explicitly  ask  to  be
  8804.             notified.)   You can  start a  large number of background
  8805.             activities  and  check  on  their  status  using  the  ps
  8806.             (process status) command.  Here's what you'd see on OS/2;
  8807.             the output under NT would be fairly similar.
  8808.  
  8809.                  551 D% ps
  8810.                  Job     ID      Parent      State          Activity
  8811.                  -       t1      -           running
  8812.                  interrupt_handler
  8813.                  -       t2      t1          running
  8814.                  thread_cleanup
  8815.                  -       t3      t1          running
  8816.                  process_cleanup
  8817.                  -       t4      t1          running
  8818.                  screen_cleanup
  8819.                  -       t5      t1          running
  8820.                  keyboard_reader
  8821.                  -       t6      t1          running
  8822.                  main_thread
  8823.                  -       t7      t1          running
  8824.                  console_io
  8825.                  3       s33     t6          running        pmcpl
  8826.  
  8827.                Threads 1  through 4  always run  in  the  background.
  8828.             Each spends most of the time asleep, waking up to do some
  8829.             housekeeping only  when an interrupt or the signal that a
  8830.             child activity  has completed  is received.   Thread 5 is
  8831.             dedicated to  reading characters  from  the  keyboard  on
  8832.             request from  other threads.   Thread 6 is the foreground
  8833.             command processor.  Thread 7 was spawned when the C shell
  8834.             realized that pmcpl is a graphical application and that a
  8835.             pipe would be needed to capture any stdio output from the
  8836.             child.  Other entries in the ps report come and go as you
  8837.             type commands.
  8838.  
  8839.                If you  want  to  explicitly  terminate  a  background
  8840.             activity, use the kill command.  But do keep in mind that
  8841.             under NT,  there are two ways to kill a process:  If it's
  8842.             a console  (text window)  application, it  can be done by
  8843.             sending it  a Ctrl-C  signal; that's  what kill  does  by
  8844.             default.   But if  it's a  graphical application,  it can
  8845.             only be  done using  the TerminateProcess  call,  a  very
  8846.             brute force way of killing something; any DLL's that were
  8847.             being used by that process will not any notification that
  8848.  
  8849.  
  8850.  
  8851.  
  8852.                                      Page 136
  8853.  
  8854.                                                                    Scheduling
  8855.  
  8856.  
  8857.             the process  has died  and, thus, will not know to do any
  8858.             cleanup they might normally do.
  8859.  
  8860.                  552 D% kill 3
  8861.                  553 D% ps
  8862.                  Job     ID      Parent      State          Activity
  8863.                  -       t1      -           running
  8864.                  interrupt_handler
  8865.                  -       t2      t1          running
  8866.                  thread_cleanup
  8867.                  -       t3      t1          running
  8868.                  process_cleanup
  8869.                  -       t4      t1          running
  8870.                  screen_cleanup
  8871.                  -       t5      t1          running
  8872.                  keyboard_reader
  8873.                  -       t6      t1          running
  8874.                  main_thread
  8875.                  -       t7      t1          running
  8876.                  console_io
  8877.  
  8878.  
  8879.  
  8880.             Variables and Threads
  8881.  
  8882.                User-defined variables  are shared  between all active
  8883.             threads unless they're declared as local:  if one changes
  8884.             a variable's  value, the  other threads  see that  change
  8885.             immediately.     Because  the   individual  threads   run
  8886.             asynchronously, this  can cause  some surprising results.
  8887.             In  this   example,  the  foreground  thread  spawns  new
  8888.             background threads  and increments  the variable i faster
  8889.             than the  children can  execute.   By the  time  any  the
  8890.             children actually  start, the loop has finished and every
  8891.             thread sees i as having the value 5.
  8892.  
  8893.                  554 D% for i = 1 to 3 do
  8894.                  555 D?    echo $i &
  8895.                  556 D? end
  8896.                  4
  8897.                  5
  8898.                  6
  8899.                  557 D% 5
  8900.                  5
  8901.                  5
  8902.  
  8903.                One solution  is to  use the  eval  statement.    eval
  8904.             parses the  text  it's  passed  at  run-time,  after  any
  8905.             variable substitutions  have  been  done.    Because  the
  8906.             ampersand is inside the quotes, its special meaning isn't
  8907.             detected until run-time.
  8908.  
  8909.                  557 D% for i = 1 to 3 do
  8910.                  558 D?    eval "echo $i &"
  8911.  
  8912.  
  8913.  
  8914.                                      Page 137
  8915.  
  8916.      Scheduling
  8917.  
  8918.  
  8919.                  559 D? end
  8920.                  7
  8921.                  8
  8922.                  9
  8923.                  560 D% 1
  8924.                  2
  8925.                  3
  8926.  
  8927.                A better solution is to make i a local variable, since
  8928.             locals are  snapshotted and  copied  when  the  child  is
  8929.             spawned:
  8930.  
  8931.                  560 D% local i;  for i = 1 to 3 do
  8932.                  561 D%    echo $i &
  8933.                  562 D% end
  8934.                  10
  8935.                  11
  8936.                  12
  8937.                  563 D% 1
  8938.                  2
  8939.                  3
  8940.  
  8941.  
  8942.  
  8943.             Re-entrancy
  8944.  
  8945.                Threads also introduce the possibility of re-entrancy.
  8946.             In the  next example,  we define  a procedure for summing
  8947.             all the  integers 1  to n.   Notice that it works fine if
  8948.             it's run  by itself,  but gives  the wrong answers if two
  8949.             threads try to run it simultaneously:
  8950.  
  8951.                  563 D% proc sum(n)
  8952.                  564 D?    @ s = 0
  8953.                  565 D?    for i = 1 to n do
  8954.                  566 D?       @ s += i
  8955.                  567 D?    end
  8956.                  568 D? end
  8957.                  569 D% sum 100
  8958.                  5050
  8959.                  570 D% sum 100 &; sum 100
  8960.                  13
  8961.                  6780
  8962.                  571 D% 7177
  8963.  
  8964.                Here  also,  the  solution  is  simply  to  include  a
  8965.             statement defining i and s as local inside the procedure.
  8966.  
  8967.  
  8968.  
  8969.             Threads:  An advanced discussion
  8970.  
  8971.                In  building   Hamilton  C   shell,  a  conscious  and
  8972.             fundamental decision  was made  to use  threads  in  many
  8973.  
  8974.  
  8975.  
  8976.                                      Page 138
  8977.  
  8978.                                                                    Scheduling
  8979.  
  8980.  
  8981.             situations  where   earlier  shells  might  have  created
  8982.             separate processes.   The  result is  a dramatically more
  8983.             responsive tool  albeit one  with  some  subtle  semantic
  8984.             differences from the original.
  8985.  
  8986.                The  UNIX  C  shell  language  definition  called  for
  8987.             individual stages  of a  pipeline, command  substitutions
  8988.             and scripts  each to  be run in a separate process cloned
  8989.             by forking  the main  process.   Using forking, the child
  8990.             inherited all  of its  parent's state (current directory,
  8991.             open file handles, environmental and set variables, etc.)
  8992.             but any  changes it made only affected itself.  On a UNIX
  8993.             system with  paging hardware and the fork mechanism built
  8994.             into the kernel, it's pretty fast.
  8995.  
  8996.                But OS/2 and the NT Win32 api's do not have fork+, and
  8997.             trying to recreate precisely this language semantic under
  8998.             OS/2  or   NT  would   have  been   foolishly  expensive,
  8999.             potentially adding  several seconds  to the  startup time
  9000.             each time you invoked a shell script.  On the other hand,
  9001.             these systems  do offer threads.  A process can have lots
  9002.             of threads  and each  one can  run along at its own pace.
  9003.             When a thread calls the kernel to do something that takes
  9004.             a long  time (e.g.,  a disk  read), it  goes to sleep and
  9005.             doesn't wake  up until the data's ready.  When one thread
  9006.             goes to sleep, the kernel looks around for another that's
  9007.             ready to  run.  By using threads, it's possible to ensure
  9008.             that if  one thing's  got to  wait, that  won't  hold  up
  9009.             everything else.
  9010.  
  9011.                Threads turn  out  to  be  even  faster  than  a  fork
  9012.             (regardless of the hardware), because the amount of state
  9013.             information  associated   with  a  thread  is  so  little
  9014.             compared to  that of a process.  As viewed by the kernel,
  9015.             a thread  ``owns'' only  a register  set, a  stack and an
  9016.             instruction pointer.   Everything  else, memory,  current
  9017.             directories, etc.,  is shared  among all the threads in a
  9018.             process.   This means  creating a thread is very fast, as
  9019.             is switching between threads.
  9020.  
  9021.                On the  other hand,  using threads  to best  advantage
  9022.             imposed some  significant design challenges in Hamilton C
  9023.             shell.   Certainly, for  example, few  would consider  it
  9024.             acceptable if  a script  running in  the background could
  9025.             >Boom< change  your foreground current disk!  The problem
  9026.             was to  create a  way for  threads to cooperatively share
  9027.             the process  resources but  without giving  away all  the
  9028.             ____________________
  9029.             + The decision  not to provide a fork semantic under OS/2
  9030.               was  probably  forced  by  the  decision  that  initial
  9031.               releases of  OS/2  would  run  on  286-based  machines.
  9032.               Lacking paging  hardware, a  fork on a 286 would likely
  9033.               have been unacceptably slow, no matter how the software
  9034.               was designed.
  9035.  
  9036.  
  9037.  
  9038.                                      Page 139
  9039.  
  9040.      Scheduling
  9041.  
  9042.  
  9043.             performance advantage we'd started with by using threads.
  9044.             Also, some of the elegance of threads is the idea you can
  9045.             keep creating new ones.  Each is just like the next:  any
  9046.             given thread  can run  just as  complex a  program as the
  9047.             next and each can spawn new threads.  It would be a shame
  9048.             to lose  that recursive  characteristic by  clumsiness in
  9049.             the language design.
  9050.  
  9051.                Starting with a clean sheet of paper, our solution was
  9052.             a highly  multi-threaded architecture.  It expects you to
  9053.             start lots  of threads:   stages  in a  pipe,  background
  9054.             activities, etc.   To  our knowledge,  no  other  command
  9055.             processor  on   any  system   employs  this   technology.
  9056.             Certainly, all  the code  in  Hamilton  C  shell  is  re-
  9057.             entrant:   there is  a  minimum  of  global,  statically-
  9058.             allocated data; the few variables that are global tend to
  9059.             be pointers to the roots of various dynamically-allocated
  9060.             information  trees   for  managing   variables,  threads,
  9061.             processes, file  handles and  other resources.   When the
  9062.             shell creates  a new  thread, it  creates the appropriate
  9063.             records and  links them  in.   Some characteristics given
  9064.             the new  thread are  inherited from  it's parent and some
  9065.             always get set to specific defaults.
  9066.  
  9067.                Shared variables  and other  resources are semaphored:
  9068.             before using  a resource,  a  thread  requests  it;    if
  9069.             several  resources  are  needed  simultaneously,  they're
  9070.             always requested  in the  same order  to avoid deadlocks.
  9071.             Critical resources  are  held  only  for  short  periods.
  9072.             There's no  polling anywhere.   ``Handle'' mechanisms are
  9073.             used so  that, e.g.,  a thread  can decide if its current
  9074.             disk and  directories are  set up  by simply comparing an
  9075.             integer.   Path hashing  structures  are  shared  with  a
  9076.             ``copy  on   write''  mechanism   in  case   they  change
  9077.             directories and  need slightly different hash structures.
  9078.             Any thread  can do what any other can: compile or execute
  9079.             an arbitrarily  complex C  shell program or even spawn or
  9080.             pipe child threads.
  9081.  
  9082.                Given the  enormous advantage  offered by  threads and
  9083.             the unique technology we've developed to exploit them, we
  9084.             expect Hamilton C shell should easily outperform any UNIX
  9085.             shell on comparable hardware.
  9086.  
  9087.  
  9088.  
  9089.  
  9090.  
  9091.  
  9092.  
  9093.  
  9094.  
  9095.  
  9096.  
  9097.  
  9098.  
  9099.  
  9100.                                      Page 140
  9101.  
  9102.                                                           Order of Evaluation
  9103.  
  9104.  
  9105.             
  9106.  
  9107.  
  9108.                                Order of Evaluation
  9109.  
  9110.  
  9111.                Finally, to  put everything  in perspective,  here's a
  9112.             summary of  roughly the  procedure by  which the  C shell
  9113.             reads, parses and evalutes your commands:
  9114.  
  9115.             1.   The command  is read.   If  stdin appears  to  be  a
  9116.                  keyboard, the command line editing routines are used
  9117.                  to read  a keystroke  at a  time, entering them into
  9118.                  the command  buffer and  doing whatever  editing  is
  9119.                  indicated.    Otherwise,  the shell  simply uses the
  9120.                  kernel's DosRead function to read small chunks until
  9121.                  the end of the statement has been found.
  9122.  
  9123.             2.   History substitution  is done.  The ``!'' and ``%''-
  9124.                  style history references are expanded.
  9125.  
  9126.             3.   The text  is broken  up into separate words.  Unless
  9127.                  it's part  of a quoted string, white space (tabs and
  9128.                  spaces)  separates   words.    Also,  these  special
  9129.                  strings are  interpreted as  separate words  even if
  9130.                  they're run together with other text:
  9131.  
  9132.                  &   |   ;   >   <   (   )   &&   ||   >>   <<   >&
  9133.                  >!   >&!
  9134.  
  9135.             4.   The command  is added to the history list.  The fact
  9136.                  that this  is done after the text has been broken up
  9137.                  into separate words explains why the commands in the
  9138.                  history list  will look a bit different than the way
  9139.                  you typed  them.   It's done  this way on purpose so
  9140.                  that you  can refer  to individual words in previous
  9141.                  commands, e.g.,  with ``!$''  to get  just the  last
  9142.                  word of the last command.
  9143.  
  9144.             5.   The command  is compiled into an internal form using
  9145.                  a recursive descent parser, recognizing the language
  9146.                  constructs and  whether a given portion of a command
  9147.                  is really an expression or just a series of words.
  9148.  
  9149.                  Compilation at this stage is at the level of a whole
  9150.                  construct, e.g.,  a whole  foreach statement or proc
  9151.                  definition and everything inside it.  That's so that
  9152.                  every time  through a loop or every time a procedure
  9153.                  is run,  the  shell  won't  waste  time  recompiling
  9154.                  statements that  could have  been compiled the first
  9155.                  time.   Also, aliases are expanded at this stage and
  9156.                  some  minor   optimizations  are  done,  e.g.,  pre-
  9157.                  compiling  static  patterns  appearing  in  pattern-
  9158.                  matching expressions, etc.
  9159.  
  9160.  
  9161.  
  9162.                                      Page 141
  9163.  
  9164.      Order of Evaluation
  9165.  
  9166.  
  9167.             6.   The internal  form is executed.  The various quoting
  9168.                  and  other  substitution  activities  are  done,  in
  9169.                  effect, in this order:
  9170.  
  9171.                  a.   Threads are  spawned for  separate stages  of a
  9172.                       pipeline or  for background  execution.  That's
  9173.                       to avoid  serializing any  blocking events  as,
  9174.                       for example,  the shell  hits the disk, looking
  9175.                       through the  search path  for executable files,
  9176.                       etc.    By  spawning  separate  threads,  those
  9177.                       blocking events can be overlapped.
  9178.  
  9179.                  b.   I/O redirection  is performed.  If the filename
  9180.                       being redirected to/from is actually a wildcard
  9181.                       or a command or some kind of substitution, that
  9182.                       word will be expanded.
  9183.  
  9184.                  c.   Single and double quoted strings are processed.
  9185.                       If the  quoted  string  contains  any  wildcard
  9186.                       characters, they're  escaped  so  that  they'll
  9187.                       appear as  literal characters  when wildcarding
  9188.                       is done  but still  be  unescaped  right  after
  9189.                       that.
  9190.  
  9191.                       In the  compiled internal  form,  double-quoted
  9192.                       strings   containing    variable   or   command
  9193.                       substitutions are  already specially  broken up
  9194.                       to look,  at this  stage, like a series double-
  9195.                       quoted strings  and substitutions  concatenated
  9196.                       together.
  9197.  
  9198.                  d.   Variable and command substitutions are done.
  9199.  
  9200.                  e.   Wildcarding is done.
  9201.  
  9202.                  f.   Escape characters are processed.
  9203.  
  9204.                  g.   The series of words is passed to the command as
  9205.                       arguments.   (It's at  this point,  if it's  an
  9206.                       eval command,  that the argument text is passed
  9207.                       back  through   the  parser  and  then  to  the
  9208.                       evaluation logic)
  9209.  
  9210.                       Commands are searched for in this order:
  9211.  
  9212.                       (1)  User-defined procedures.
  9213.  
  9214.                       (2)  Built-in procedures and commands.
  9215.  
  9216.                       (3)  External commands,  searched  for  in  the
  9217.                            PATH directories in this order within each
  9218.                            directory:
  9219.  
  9220.                               .csh   .exe   .com   .cmd   .bat
  9221.  
  9222.  
  9223.  
  9224.                                      Page 142
  9225.  
  9226.                                                           Order of Evaluation
  9227.  
  9228.  
  9229.                            (.bat files can be run only under OS/2 2.x
  9230.                            or Windows NT.)
  9231.  
  9232.             7.   The internal  form of  each  compiled  statement  is
  9233.                  discarded once  it's  no  longer  needed,  i.e.,  if
  9234.                  there's no  way you  might invoke  that code  from a
  9235.                  later statement.
  9236.  
  9237.                  For example,  once  you  define  a  procedure,  it's
  9238.                  always accessible;  you can  call it at any time, so
  9239.                  that compiled  code is  never discarded  unless  you
  9240.                  redefine the procedure or explicitly unproc it.  But
  9241.                  an ordinary  statement typed  at  the  command  line
  9242.                  could  be   re-run  (without  re-entering  it  using
  9243.                  history or  by retyping it) only if it was part of a
  9244.                  larger control  structure or  if there  was a way to
  9245.                  goto it,  meaning there  would have  to have  been a
  9246.                  label preceding it.
  9247.  
  9248.  
  9249.  
  9250.  
  9251.  
  9252.  
  9253.  
  9254.  
  9255.  
  9256.  
  9257.  
  9258.  
  9259.  
  9260.  
  9261.  
  9262.  
  9263.  
  9264.  
  9265.  
  9266.  
  9267.  
  9268.  
  9269.  
  9270.  
  9271.  
  9272.  
  9273.  
  9274.  
  9275.  
  9276.  
  9277.  
  9278.  
  9279.  
  9280.  
  9281.  
  9282.  
  9283.  
  9284.  
  9285.  
  9286.                                      Page 143
  9287.  
  9288.      Customizing the Shell
  9289.  
  9290.  
  9291.             
  9292.  
  9293.  
  9294.                               Customizing the Shell
  9295.  
  9296.  
  9297.                Depending on  your tastes and what you're used to (and
  9298.             whether you  come from  a  DOS  or  a  UNIX  background),
  9299.             Hamilton C  shell can  be customized in a number of ways.
  9300.             This section will outline:
  9301.  
  9302.                1.  Various  options  you  have  when  installing  the
  9303.                    shell, including  setting it  up  as  the  default
  9304.                    command processor,
  9305.  
  9306.                2.  How shell starts up, and how it uses the login.csh
  9307.                    and startup.csh files,
  9308.  
  9309.                3.  How to  set the  environmental  variables,  screen
  9310.                    colors and the prompt strings,
  9311.  
  9312.                4.  How to create aliases you always want available,
  9313.  
  9314.                5.  Customizing  the   cd  command   and  how  history
  9315.                    references work, and
  9316.  
  9317.                6.  Telling the shell how it should respond to certain
  9318.                    special situations.
  9319.  
  9320.  
  9321.  
  9322.             Installation Options
  9323.  
  9324.                You have  a fair  amount of  choice  about  where  the
  9325.             various files  associated with  Hamilton C  shell go  and
  9326.             also about  how it starts up.  You won't necessarily want
  9327.             to fool  with all  this when you first install the shell,
  9328.             but you  may want  to look  at some  of this as you get a
  9329.             sense of your own preferences.
  9330.  
  9331.                The C  shell .exe  and .csh  files can  go anywhere as
  9332.             long as they're on your search path.  Most people find it
  9333.             most convenient to keep them in a separate directory.  We
  9334.             do suggest  it be  ahead of  the directory containing the
  9335.             standard more.com  on your search path since we provide a
  9336.             new, vastly improved more.
  9337.  
  9338.                You choose any directory on any drive as your ``home''
  9339.             directory.   The significance of a home directory is that
  9340.             the shell  will make  references to  it or relative to it
  9341.             very  convenient  using  the  ``~''  wildcard  character.
  9342.             Also,  this  is  where  the  shell  will  look  for  your
  9343.             login.csh and  startup.csh files.   If HOME isn't defined
  9344.             in the  environment when the shell starts up, it defaults
  9345.  
  9346.  
  9347.  
  9348.                                      Page 144
  9349.  
  9350.                                                         Customizing the Shell
  9351.  
  9352.  
  9353.             to the  current directory.   It's usually most convenient
  9354.             to define the HOME variable in your config.sys but if you
  9355.             prefer, you  can pass it to the shell on the command line
  9356.             using ``-C  setenv HOME=...''   (The  ``-C''  means  what
  9357.             follows is a command.)
  9358.  
  9359.                Additional customization  is  usually  done  with  the
  9360.             login.csh and startup.csh files.
  9361.  
  9362.  
  9363.  
  9364.             Installing as the Default OS/2 Command Processor
  9365.  
  9366.                OS/2 gives  whatever  default  command  processor  you
  9367.             specify on  the PROTSHELL line of your config.sys special
  9368.             privileges to  change its  own title  bar and, under OS/2
  9369.             1.3 or  2.x, its  own icon.   This can be quite useful if
  9370.             you have  a lot  of copies of the shell running minimized
  9371.             and you'd like to know what they're doing.
  9372.  
  9373.                Under  OS/2   1.1  or   1.2,  the  C  shell  uses  the
  9374.             undocumented DosSMSetTitle kernel api entry to change its
  9375.             own  title;   under  1.3   or  2.x,   it  uses   the  new
  9376.             WinSetTitleAndIcon api to change both the title and icon.
  9377.             Unfortunately, these  api entries  are disabled if you're
  9378.             not running  in a  window  whose  root  process  was  the
  9379.             default command processor.
  9380.  
  9381.                To  install   the  C  shell  as  the  default  command
  9382.             processor,  follow   the  instructions   given   in   the
  9383.             installation section  of this manual.  In a nutshell, the
  9384.             idea is  to replace  the reference  to  cmd.exe  and  any
  9385.             parameters to  cmd.exe  on  the  PROTSHELL  or  OS2_SHELL
  9386.             (under 2.x)  line with  the full  pathname of the C shell
  9387.             plus a ``-L'' option to indicate it's a login shell.
  9388.  
  9389.                Next, fixup the entries for cmd.exe and the C shell in
  9390.             the Group-Main  or Start  Programs menus.   To  make it a
  9391.             default command  processor, the  C shell  must be  listed
  9392.             with an  ``*'' (asterisk)  for a  pathname (on the ``Path
  9393.             and file  name:'' line  if you  pull-down ``Program'' and
  9394.             select ``Properties...'  in Group-Main) or else the title
  9395.             bar and  icon changes  will be  disabled.  Also, for some
  9396.             reason, if you specify any startup parameters (other than
  9397.             ``/K "%*"''), that  also  disables  the  title  and  icon
  9398.             changes.      (The   ``/K "%*"''   option   has   special
  9399.             significance for  the default  command processor  and  is
  9400.             used when OS/2 boots up if it finds a startup.cmd file in
  9401.             the root directory; otherwise, it's ignored.)
  9402.  
  9403.                Conversely, you  have to  change the asterisk path and
  9404.             any arguments  for the cmd.exe entries to the actual path
  9405.             for cmd.exe and enter whatever arguments (if any) you had
  9406.  
  9407.  
  9408.  
  9409.  
  9410.                                      Page 145
  9411.  
  9412.      Customizing the Shell
  9413.  
  9414.  
  9415.             been specifying for it on the PROTSHELL or OS2_SHELL line
  9416.             in your config.sys.
  9417.  
  9418.  
  9419.  
  9420.             login.csh
  9421.  
  9422.                login.csh is  read only  by copies  of csh.exe started
  9423.             with the ``-L'' option to make them login or root shells.
  9424.             Typically, this  is a new window.  startup.csh is read by
  9425.             each new  copy of  the shell,  even if  it's invoked as a
  9426.             child of the C shell.
  9427.  
  9428.                The main objective of the login.csh file is to let you
  9429.             set up  those characteristics  that are  inheritable from
  9430.             parent to  child process but which might not be set up if
  9431.             you're starting  from the Start Programs menu (OS/2 1.1),
  9432.             a Group  menu (OS/2  1.2 or  1.3),from the  desktop (OS/2
  9433.             2.x) or  from the  Program  Manager  (Windows  NT).    In
  9434.             addition, it  lets you  do a little special customization
  9435.             of these highest-level shells.
  9436.  
  9437.                The  important  inheritable  characteristics  are  the
  9438.             environmental  variables   together  with   the   current
  9439.             directories and current disk settings.
  9440.  
  9441.  
  9442.  
  9443.  
  9444.  
  9445.  
  9446.  
  9447.  
  9448.  
  9449.  
  9450.  
  9451.  
  9452.  
  9453.  
  9454.  
  9455.  
  9456.  
  9457.  
  9458.  
  9459.  
  9460.  
  9461.  
  9462.  
  9463.  
  9464.  
  9465.  
  9466.  
  9467.  
  9468.  
  9469.  
  9470.  
  9471.  
  9472.                                      Page 146
  9473.  
  9474.                                                         Customizing the Shell
  9475.  
  9476.  
  9477.             The Environmental Variables
  9478.  
  9479.                Most  users   prefer  to  create  the  bulk  of  their
  9480.             environmental variables with SET statements in config.sys
  9481.             under OS/2  or through the Control Panel under Windows NT
  9482.             (to be  inherited by  every process on the system) rather
  9483.             than in  login.csh.   It  means  just  one  copy  of  the
  9484.             definitions in one place, so it's easier to make changes.
  9485.             It also  runs faster since it's all set up when the shell
  9486.             starts; the  shell doesn't  have read all those commands.
  9487.             But if  you're using an initialization script to set some
  9488.             of your  environmentals for  cmd.exe, you'll  want to  do
  9489.             that for the C shell also in login.csh.
  9490.  
  9491.                But there  are cases where it's more convenient to set
  9492.             up some  environmental in  your login.csh.   For example,
  9493.             you might prefer to set your PATH statement there.  Since
  9494.             the C  shell hashes  your search  path, you'll  find it's
  9495.             much faster  finding things even with a very long list of
  9496.             path  directories.    (If  you  actually  had  50  or  so
  9497.             directories, the difference in startup time for something
  9498.             in that  last directory would be around 6 seconds or so!)
  9499.             So you  might find  it more natural to have a much longer
  9500.             PATH with the C shell than with cmd.exe.
  9501.  
  9502.                Also, if  you were  going to  use an  application that
  9503.             needed mixed  case characters  in some of its environment
  9504.             strings and  you were  running on OS/2 1.1, you'd want to
  9505.             define them  in login.csh, not config.sys.   (Using lower
  9506.             case characters in config.sys was unreliable on OS/2 1.1;
  9507.             many users  found it caused random system failures, e.g.,
  9508.             OS/2 crashing while formatting a series of floppies.)
  9509.  
  9510.                In addition  to PATH, the environmental variables used
  9511.             by Hamilton  C shell  include HOME,  PROMPT1 and PROMPT2,
  9512.             TABS, CDPATH, DRIVEMASK, MIXEDCASEDRIVES, SWITCHCHARS and
  9513.             a number of screen color configuration variables.
  9514.  
  9515.                PROMPT1  or  PROMPT2  or  their  aliases  prompt1  and
  9516.             prompt2 control  the prompt  strings you'll see for a new
  9517.             command or a continuation line.
  9518.  
  9519.                TABS is used by more.exe, head.exe, tail.exe and other
  9520.             utilities to  expand out  any tab characters it sees into
  9521.             space characters  on the  screen.    For example, setting
  9522.             TABS = 3 means tabstops every 3 character cells.
  9523.  
  9524.                CDPATH is  used by  cd  and  pushd  to  specify  other
  9525.             directories in addition to the current directory in which
  9526.             to search  for a subdirectory you're trying to change to.
  9527.             Its format  is the  same as  that as  PATH:   a  list  of
  9528.             directories separated  by colons,  but there's no need to
  9529.             list the current directory.
  9530.  
  9531.  
  9532.  
  9533.  
  9534.                                      Page 147
  9535.  
  9536.      Customizing the Shell
  9537.  
  9538.  
  9539.                DRIVEMASK lets  you confine the default list of drives
  9540.             you want  searched when you wildcard a driveletter (e.g.,
  9541.             ``*:\hamilton'') or  reported on  by the  du, pwd and vol
  9542.             utilities.   The value  should be  a list  of  upper-  or
  9543.             lower-case alphabetic  characters or ranges of characters
  9544.             representing  the  drives  you're  interested  in.    For
  9545.             example, setting  DRIVEMASK = cf-h means  you want drives
  9546.             C:, F:, G: and H: reported, assuming they exist.
  9547.  
  9548.                MIXEDCASEDRIVES is  used by  ls.exe,  by  the  shell's
  9549.             fullname and  wildcarding functions  (including  filename
  9550.             completion), by  the  current  directory  functions  (cd,
  9551.             pushd, popd and dirs) and by pwd.exe to tell which drives
  9552.             you want  reported in  the actual  upper  or  lower  case
  9553.             characters returned by the OS/2 kernel.  If you have HPFS
  9554.             or NTFS  drives, it's  possible to  create filenames that
  9555.             have mixed  upper and  lower characters  and you  may not
  9556.             want these  all routinely shifted to lower case.  You set
  9557.             MIXEDCASEDRIVES just  like DRIVEMASK, giving it a list of
  9558.             drives.  It's also possible to list UNC names that should
  9559.             be considered mixed case.  For example, typing
  9560.  
  9561.                  setenv MIXEDCASEDRIVES = [a-z],\\
  9562.  
  9563.             sets all  drive a:  through z:  and all  UNC names on all
  9564.             networked machines as mixed case.  Or for example, typing
  9565.  
  9566.                  setenv MIXEDCASEDRIVES = \\alpha,\\ps2\d^$
  9567.  
  9568.             sets all  the drives on the alpha machine and only the d:
  9569.             drive on ps2 as mixed case.  You can list as many entries
  9570.             in MIXEDCASEDRIVES,  separated by  commas, semicolons  or
  9571.             spaces, as you wish.
  9572.  
  9573.                SWITCHCHARS is used by the shell and all the utilities
  9574.             supplied with  it to  indicate what characters you intend
  9575.             as introducing  one of  the option switches.  By default,
  9576.             the C  shell tries to satisfy users coming from both DOS,
  9577.             OS/2 or  NT and  UNIX backgrounds  and will accept either
  9578.             ``-'' (DOS-style) or ``/'' (UNIX-style) as introducing an
  9579.             option.  Folks coming from a straight UNIX background may
  9580.             find that  inconvenient, particularly  if they're used to
  9581.             typing filenames  using the  forward slash;   ``cd /foo''
  9582.             will certainly  not do  what they want, for example.  The
  9583.             solution is  to ``setenv  SWITCHCHARS = -'', causing only
  9584.             those words that start ``-'' to be recognized as options.
  9585.  
  9586.  
  9587.  
  9588.             Prompt Strings
  9589.  
  9590.                Prompt strings  are  fairly  personal  matter.    This
  9591.             really is  beauty in the eye of the beholder only!  There
  9592.             are two prompt situations:
  9593.  
  9594.  
  9595.  
  9596.                                      Page 148
  9597.  
  9598.                                                         Customizing the Shell
  9599.  
  9600.  
  9601.                1.  The main  prompt, when  the shell  expects  a  new
  9602.                    command.  Set this with PROMPT1.
  9603.  
  9604.                2.  Continuation lines,  where the shell is collecting
  9605.                    more text  before running  something.   An example
  9606.                    would be  whatever  commands  you  type  inside  a
  9607.                    foreach loop.  Set this with PROMPT2.
  9608.  
  9609.                When the  shell needs  to prompt  you, it looks at the
  9610.             appropriate PROMPTx string and evaluates it as if it were
  9611.             looking at  a  double  quoted  string.    Any  backquoted
  9612.             strings or  variable substitutions  it  finds  there  are
  9613.             evaluated and whatever results is printed.  Wildcards are
  9614.             not replaced  nor is  the spacing  affected.   It's quite
  9615.             literally  double-quoted:    the  shell  actually  pastes
  9616.             double quote  characters around the string before passing
  9617.             it to the parser.
  9618.  
  9619.                If you  always wanted  the same  literal  text  string
  9620.             displayed, that  would  be  easy  but  probably  not  too
  9621.             interesting:
  9622.  
  9623.                  571 D% set PROMPT1 = "Hello from CSH!  "
  9624.                  Hello from CSH!  _
  9625.  
  9626.                The  difficult   part  of   setting  your   prompt  is
  9627.             remembering that  if you want a substitution re-evaluated
  9628.             each time  a new prompt is printed, you have to quote the
  9629.             string when  you  define  it  to  defer  the  evaluation.
  9630.             Here's the  wrong, then the right way to create a default
  9631.             IBM-style  prompt  with  your  current  directory  inside
  9632.             rectangular brackets.
  9633.  
  9634.                  Hello from CSH!  set PROMPT1 = "[$upper(cwd)] " #
  9635.                  Wrong way
  9636.                  [D:\DOUG] cdd c:\      # Notice that the prompt
  9637.                  won't change
  9638.                  [D:\DOUG] set PROMPT1 '[$upper(cwd)] ' # Right way
  9639.                  [C:\] _
  9640.  
  9641.                Notice how we're using the built-in upper procedure as
  9642.             if it  were a  variable substitution  with the  ``$''  in
  9643.             front.   When the  shell sees  it's  really  a  procedure
  9644.             reference, what's  inside the parentheses is evaluated as
  9645.             an expression  list.   That's why the cwd variable didn't
  9646.             need its own ``$.''
  9647.  
  9648.                There's really  no limit  to what you can put inside a
  9649.             prompt string.   You  can have  command substitution  and
  9650.             special characters.  It can  even stretch  over  multiple
  9651.             lines if  you put  in carriage  return/newline  character
  9652.             combinations:
  9653.  
  9654.  
  9655.  
  9656.  
  9657.  
  9658.                                      Page 149
  9659.  
  9660.      Customizing the Shell
  9661.  
  9662.  
  9663.                  [C:\] set PROMPT1 = '`date`^r^n$cwd '
  9664.                  Mon Oct 23 1989 11:15:15.03
  9665.                  c:\ _
  9666.  
  9667.                The tradeoff  to  remember  in  creating  your  prompt
  9668.             string is  that whatever you put there is going to be run
  9669.             every time  you need  a new  prompt.   If you make it too
  9670.             complex, it'll  still run,  but it  could  be  annoyingly
  9671.             slow.   Remember that  it takes  longer to  run  external
  9672.             programs than  to use  shell variables or procedures.  If
  9673.             you  want   something  really   unusual,  try  writing  a
  9674.             procedure that  calculates and  returns  the  string  you
  9675.             want.
  9676.  
  9677.  
  9678.  
  9679.             User-Defined Colors
  9680.  
  9681.                All of  the screen  colors used by the C shell and any
  9682.             of the utilities are completely under your control.  Here
  9683.             are the  variables that  control the  color settings  and
  9684.             default values:
  9685.  
  9686.                Name         Use                        Default
  9687.  
  9688.                ADDITIONS    Lines added found by diff. Bright Green
  9689.                COLORS       Normal screen colors.      White on Black
  9690.                DELETIONS    Lines deleted found by diff. Bright Red
  9691.                DIRECTORIES  Directories listed by ls.  Bright
  9692.                DUPLICATES   When filename completion matches  Green
  9693.                             more than one name.
  9694.                FOREIGNFILES Filetypes in a tar file that have no   Br
  9695.                ight Red
  9696.                             counterpart on OS/2 or NT.
  9697.                HIGHLIGHT    Current disk or directory. Bright
  9698.                MATCHFAIL    When filename or command completion    Br
  9699.                ight Red
  9700.                             doesn't match anything.
  9701.                MOREEOF      End or Top of File in more.  Green
  9702.                MOREERROR    Unrecognizable command to more.   Bright
  9703.                Yellow
  9704.                MOREFILLIN   User response to more prompt.     White
  9705.                MOREPROMPT   Prompt line in more.       Green
  9706.                MORETOPMEM   Top of Memory message from more.  Bright
  9707.                Yellow
  9708.                SYSTEMDIRS   Directories with the System bit on.    Br
  9709.                ight Green
  9710.                SYSTEMFILES   Files with the System bit on.    Green
  9711.  
  9712.                You can  choose any  color combinations  you like from
  9713.             the following  set:   black, red,  green,  yellow,  blue,
  9714.             magenta (or blue red), cyan (or blue green) and white.
  9715.  
  9716.  
  9717.  
  9718.  
  9719.  
  9720.                                      Page 150
  9721.  
  9722.                                                         Customizing the Shell
  9723.  
  9724.  
  9725.                Foreground colors  may also  be bright,  dim  (meaning
  9726.             simply, ``not  bright''), blink  or reverse.  The keyword
  9727.             ``on'' introduces  background colors.   Blink only causes
  9728.             true blinking  full-screen; in  a text  window,  it  just
  9729.             makes the  background brighter.   Also,  yellow is a true
  9730.             yellow only if it's bright.  These are system limitations
  9731.             not related to the C shell.
  9732.  
  9733.                The names  of the colors and the keywords bright, dim,
  9734.             blink, reverse  and on  are not case sensitive and may be
  9735.             typed  in   any  combination   of  upper  or  lower  case
  9736.             characters.   The names  of the  environmental  variables
  9737.             themselves must be all in upper case.
  9738.  
  9739.                If  a   foreground  or   background  color   is   left
  9740.             unspecified, that  plane is  considered  transparent  and
  9741.             inherits the color underneath it.
  9742.  
  9743.                You can  set the colors either from within the C shell
  9744.             itself by simply typing the appropriate setenv statements
  9745.             or by  including them  in your login.csh file.  Here's an
  9746.             example color  scheme that's  a little more colorful than
  9747.             the defaults:
  9748.  
  9749.                  setenv  COLORS    =  white on blue
  9750.                  setenv  DELETIONS =  bright white on red
  9751.                  setenv  ADDITIONS =  bright white on green
  9752.                  setenv  MOREPROMPT   =   red on white
  9753.                  setenv  MOREFILLIN   =   black
  9754.                  setenv  MOREERROR =  bright white on red
  9755.  
  9756.                On OS/2, you might also choose to place these settings
  9757.             into your config.sys as the corresponding SET statements:
  9758.  
  9759.                  SET     COLORS=WHITE ON BLUE
  9760.                  SET     DELETIONS=BRIGHT WHITE ON RED
  9761.                  SET     ADDITIONS=BRIGHT WHITE ON GREEN
  9762.                  SET     MOREPROMPT=RED ON WHITE
  9763.                  SET     MOREFILLIN=BLACK
  9764.                  SET     MOREERROR=BRIGHT WHITE ON RED
  9765.  
  9766.             (Notice that  if you  choose to  use  SET  statements  in
  9767.             config.sys, you  should be  sure not  to leave  any space
  9768.             around the equal signs.  Also, unless you're running OS/2
  9769.             1.2 or later, type everything in upper case.)
  9770.  
  9771.                Or, on  Windows  NT,  these  settings  could  be  made
  9772.             through the Control Panel.
  9773.  
  9774.  
  9775.  
  9776.             Initial Current Directories
  9777.  
  9778.  
  9779.  
  9780.  
  9781.  
  9782.                                      Page 151
  9783.  
  9784.      Customizing the Shell
  9785.  
  9786.  
  9787.                The login.csh  file is  also a convenient place to set
  9788.             up all  you  initial  current  directories.    The  Start
  9789.             Programs menu  lets you specify a particular current disk
  9790.             and directory  but not  what your current directories are
  9791.             on the  other  disks  when  you  start  up;  the  current
  9792.             directories  on  those  other  disks  are  always  ``\''.
  9793.             Generally, people find it convenient to be able to choose
  9794.             something  else   and  they   do  this   by  putting  the
  9795.             appropriate ``cd'' statements in login.csh.
  9796.  
  9797.                The final  use for  login.csh is in setting up certain
  9798.             local variables  that you  want different  in  the  login
  9799.             shell.   For example,  a login  shell  normally  dumps  a
  9800.             history list when it exits; you may want to turn this off
  9801.             by setting  savehist = 0.  Also, you may not want an end-
  9802.             of-file (from accidentally hitting ^Z once to many times)
  9803.             to cause  the shell to exit; you can tell to insist on an
  9804.             exit statement by setting ignoreeof = 1.
  9805.  
  9806.  
  9807.  
  9808.             startup.csh
  9809.  
  9810.                The startup.csh  file is  read by  all copies of the C
  9811.             shell, not just login or root level copies.  If you don't
  9812.             want the startup file read, you have to specifically tell
  9813.             it with  the ``-F'' (Faster startup) option.  startup.csh
  9814.             is read  after login.csh  whenever both  are being  read.
  9815.             This means  you can depend on the environmental variables
  9816.             being set up already when the startup file runs.
  9817.  
  9818.                startup.csh is  a good  place to define any aliases or
  9819.             function key  definitions you  use, since  you'd probably
  9820.             always want  them available  but can't  pass them  in the
  9821.             environment  to   any  child  copies  of  csh.exe.    The
  9822.             startup.csh file  that comes  with the  shell  defines  a
  9823.             number of  popular aliases  including some for getting at
  9824.             some of  cmd.exe's internal  functions; most people add a
  9825.             few of their own.
  9826.  
  9827.                The  other   thing  you   may  want  to  add  to  your
  9828.             startup.csh  file  are  settings  for  some  of  the  set
  9829.             variables that  customize how  the  shell  runs.    These
  9830.             aren't passed in the environment.  Look through the lists
  9831.             in the  Language Reference section.  Some you may want to
  9832.             set differently than the defaults are bsdhistory, cdhome,
  9833.             chgdisk,     escapesym,      histchars,     ignoreerrors,
  9834.             ignorestatus,   noclobber,   nonomatch,   nullwords   and
  9835.             tailstatus.   A lot  of what  you choose  will depend  on
  9836.             whether you're coming from a DOS or a UNIX background.
  9837.  
  9838.  
  9839.  
  9840.             Change Directory
  9841.  
  9842.  
  9843.  
  9844.                                      Page 152
  9845.  
  9846.                                                         Customizing the Shell
  9847.  
  9848.  
  9849.                If your  background is DOS, you'll probably want cd to
  9850.             just report the current directory if you don't give it an
  9851.             argument.   Those with  a UNIX  background may want it to
  9852.             mean ``change  to the  home disk and directory.''  That's
  9853.             determined with  the cdhome  variable; the  default is  a
  9854.             DOS-style reporting only.
  9855.  
  9856.                Another customization you may to do is to intercept cd
  9857.             so that  you can  capture  your  last  current  directory
  9858.             whenever you change directories:
  9859.  
  9860.                  proc cd(dest)
  9861.                     @ lwd = cwd    # capture the last working
  9862.                  directory
  9863.                     if ($dest == "")
  9864.                        chdir
  9865.                     else
  9866.                        chdir $dest
  9867.                     end
  9868.                  end
  9869.  
  9870.  
  9871.  
  9872.             Berkeley-style History and Escapes
  9873.  
  9874.                Also, if your fingers learned to use the ``!-n'' style
  9875.             of history  references on  a Berkeley UNIX system, you'll
  9876.             want to  set  bsdhistory = 1.  True die-hard (and perhaps
  9877.             daring) former  UNIX  users  may  want  try  setting  the
  9878.             escapesym back  to a  backslash; it'll  work with  the  C
  9879.             shell but  you're on  your own with other applications or
  9880.             tools.
  9881.  
  9882.  
  9883.  
  9884.             Berkeley Compatibility Mode
  9885.  
  9886.                Hamilton C  shell does  implement a substantial number
  9887.             of significant  improvements over the original Berkeley C
  9888.             shell.   By and large, we expect most users to find these
  9889.             changes welcome.   But  if you're  trying to run a script
  9890.             developed using  the Berkeley  C shell  or if  you simply
  9891.             want get  a more precise ``Berkeley mode'' interactively,
  9892.             you can do that.
  9893.  
  9894.                Following a  common convention  on UNIX that the first
  9895.             line of  a script  can identify the language processor to
  9896.             be used  with it, if the C shell encounters a script that
  9897.             starts with
  9898.  
  9899.                  #!/bin/csh
  9900.  
  9901.             it will  shift to  a  fairly  precise  emulation  of  the
  9902.             original Berkeley C shell.
  9903.  
  9904.  
  9905.  
  9906.                                      Page 153
  9907.  
  9908.      Customizing the Shell
  9909.  
  9910.  
  9911.                To enter  this mode  for interactive work, start the C
  9912.             shell with the ``-B'' (Berkeley compatibility) option.
  9913.  
  9914.                For more  details on  differences between the Hamilton
  9915.             and Berkeley C shells and on Berkeley compatibility mode,
  9916.             please  please   refer  to   the  Compatibility   section
  9917.             beginning on page 155.
  9918.  
  9919.  
  9920.  
  9921.             Error Handling
  9922.  
  9923.                ignoreerrors, ignorestatus,  noclobber, nonomatch  and
  9924.             nullwords let  you  tailor  how  the  shell  responds  to
  9925.             various exception  situations.   They let  you  determine
  9926.             whether  you  think  certain  things  are  errors.    For
  9927.             example, should  a child  process that returns a non-zero
  9928.             return code but otherwise seems to run okay be considered
  9929.             an error?   If  you set  ignorestatus =  0, it  will  be.
  9930.             Similarly,  noclobber   lets  you   intercept  accidental
  9931.             attempts  to   overwrite  an   existing  file   with  i/o
  9932.             redirection.   nonomatch  tells  what  should  happen  if
  9933.             wildcarding doesn't  match  anything.    nullwords  tells
  9934.             whether you think it's an error to use a subscript that's
  9935.             off the end of an array.
  9936.  
  9937.  
  9938.  
  9939.             Calling the C shell from Other Applications
  9940.  
  9941.                Many applications,  e.g., editors,  make utilities and
  9942.             so on,  depend on  being able  to  call  up  the  command
  9943.             processor.   For example,  make uses  cmd.exe to actually
  9944.             process each  command in the make file that it determines
  9945.             should  be   run.     Most  editors   (and   many   other
  9946.             applications) provide  a way  of  temporarily  suspending
  9947.             themselves and  invoking cmd.exe  so you  can run  a  few
  9948.             commands and then exit to return back to the editor.
  9949.  
  9950.                Usually,  these   applications  look  at  the  COMSPEC
  9951.             environmental variable to determine the full pathname for
  9952.             cmd.exe.   If, like  make, they're just calling it with a
  9953.             single command on the command line, they use cmd.exe's /C
  9954.             option.
  9955.  
  9956.                If you'd  like to  use the  C shell instead of cmd.exe
  9957.             with these  applications, set  COMSPEC to  point to the C
  9958.             shell  instead   and  use  the  CSHOPTIONS  environmental
  9959.             variable to  tell the  C shell to interpret the /C option
  9960.             flag in  a way that's compatible with the meaning cmd.exe
  9961.             would attach to it:
  9962.  
  9963.                  setenv COMSPEC = c:\hamilton\bin\csh.exe
  9964.                  setenv CSHOPTIONS = -X
  9965.  
  9966.  
  9967.  
  9968.                                      Page 154
  9969.  
  9970.                                                         Customizing the Shell
  9971.  
  9972.  
  9973.                Alternately, you  can put these definitions right into
  9974.             your standard  environment using  the NT System applet in
  9975.             the control  panel or  by adding these statements to your
  9976.             OS/2 config.sys:
  9977.  
  9978.                  set COMSPEC=c:\hamilton\bin\csh.exe
  9979.                  set CSHOPTIONS=-X
  9980.  
  9981.                When the  C shell  starts up,  if  it  discovers  that
  9982.             COMSPEC points to itself, it will look through the search
  9983.             path to  find the  real cmd.exe.  This is to make sure it
  9984.             will still  be able  to run  .cmd files.   Since  the  -X
  9985.             option is  a toggling  option, you  can still  get at the
  9986.             original meaning of the -C option by typing -XC to toggle
  9987.             back.
  9988.  
  9989.  
  9990.  
  9991.  
  9992.  
  9993.  
  9994.  
  9995.  
  9996.  
  9997.  
  9998.  
  9999.  
  10000.  
  10001.  
  10002.  
  10003.  
  10004.  
  10005.  
  10006.  
  10007.  
  10008.  
  10009.  
  10010.  
  10011.  
  10012.  
  10013.  
  10014.  
  10015.  
  10016.  
  10017.  
  10018.  
  10019.  
  10020.  
  10021.  
  10022.  
  10023.  
  10024.  
  10025.  
  10026.  
  10027.  
  10028.  
  10029.  
  10030.                                      Page 155
  10031.  
  10032.      Customizing the Shell
  10033.  
  10034.  
  10035.  
  10036.                                         
  10037.  
  10038.  
  10039.  
  10040.  
  10041.  
  10042.  
  10043.  
  10044.  
  10045.  
  10046.  
  10047.  
  10048.  
  10049.  
  10050.  
  10051.  
  10052.  
  10053.  
  10054.  
  10055.  
  10056.  
  10057.  
  10058.  
  10059.  
  10060.  
  10061.  
  10062.  
  10063.  
  10064.  
  10065.  
  10066.  
  10067.  
  10068.  
  10069.  
  10070.  
  10071.  
  10072.  
  10073.  
  10074.  
  10075.  
  10076.  
  10077.  
  10078.  
  10079.  
  10080.  
  10081.  
  10082.  
  10083.  
  10084.  
  10085.  
  10086.  
  10087.  
  10088.  
  10089.  
  10090.  
  10091.  
  10092.                                      Page 156
  10093.  
  10094.                                                                       Summary
  10095.  
  10096.  
  10097.  
  10098.                                         
  10099.  
  10100.  
  10101.  
  10102.  
  10103.                                      Summary
  10104.  
  10105.  
  10106.                The next  few pages  show a  couple of  somewhat  more
  10107.             full-blown examples  and  outline  the  contents  of  the
  10108.             samples directory.   There's  also detailed discussion of
  10109.             the  compatibility   issues  between   the  Hamilton  and
  10110.             original Berkeley C shells.
  10111.  
  10112.                Try some  experiments.    We  hope  you'll  find  this
  10113.             product powerful,  fast, reliable  and easy  to use.   We
  10114.             hope it  will help  you get  your work  done  faster  and
  10115.             perhaps, more pleasantly.
  10116.  
  10117.  
  10118.  
  10119.  
  10120.  
  10121.  
  10122.  
  10123.  
  10124.  
  10125.  
  10126.  
  10127.  
  10128.  
  10129.  
  10130.  
  10131.  
  10132.  
  10133.  
  10134.  
  10135.  
  10136.  
  10137.  
  10138.  
  10139.  
  10140.  
  10141.  
  10142.  
  10143.  
  10144.  
  10145.  
  10146.  
  10147.  
  10148.  
  10149.  
  10150.  
  10151.  
  10152.  
  10153.  
  10154.                                      Page 157
  10155.  
  10156.      Summary
  10157.  
  10158.  
  10159.                                         
  10160.  
  10161.  
  10162.  
  10163.  
  10164.  
  10165.  
  10166.  
  10167.  
  10168.  
  10169.  
  10170.  
  10171.  
  10172.  
  10173.  
  10174.  
  10175.  
  10176.  
  10177.  
  10178.  
  10179.  
  10180.  
  10181.  
  10182.  
  10183.  
  10184.  
  10185.  
  10186.  
  10187.  
  10188.  
  10189.  
  10190.  
  10191.  
  10192.  
  10193.  
  10194.  
  10195.  
  10196.  
  10197.  
  10198.  
  10199.  
  10200.  
  10201.  
  10202.  
  10203.  
  10204.  
  10205.  
  10206.  
  10207.  
  10208.  
  10209.  
  10210.  
  10211.  
  10212.  
  10213.  
  10214.  
  10215.  
  10216.                                      Page 158
  10217.  
  10218.                                                                      Examples
  10219.  
  10220.  
  10221.             
  10222.  
  10223.  
  10224.                                     Examples
  10225.  
  10226.  
  10227.             Factor.csh:  A self-loading procedure which prints a list
  10228.             of the  factors of  a number,  illustrating  the  use  of
  10229.             recursion.
  10230.  
  10231.                 
  10232.                 proc factor(n)
  10233.                   if (n > 2) then
  10234.                      for i = 2 to floor(sqrt(n)) do
  10235.                         if (n % i == 0) then
  10236.                            echo $i
  10237.                             return factor(n/i)
  10238.                         end
  10239.                      end
  10240.                   end
  10241.                   return n
  10242.                 end
  10243.                 
  10244.                 factor $argv
  10245.  
  10246.             Invoked as:
  10247.  
  10248.                 factor 6324489
  10249.  
  10250.             It would print:
  10251.  
  10252.                 3
  10253.                 3
  10254.                 702721
  10255.  
  10256.             To print  the factors  on one  line and  time how long it
  10257.             takes:
  10258.  
  10259.                 time echo `factor 6324489`
  10260.  
  10261.             The `...`  sequence  means  command  substitution:    run
  10262.             what's inside  the backquotes  and substitute  the output
  10263.             back onto the command line.  This would print:
  10264.  
  10265.                 3 3 702721
  10266.                 0:00:02.35
  10267.  
  10268.  
  10269.  
  10270.  
  10271.  
  10272.  
  10273.  
  10274.  
  10275.  
  10276.  
  10277.  
  10278.                                      Page 159
  10279.  
  10280.      Examples
  10281.  
  10282.  
  10283.             
  10284.             
  10285.             Whereis.csh:   A self-loading  procedure to  find all the
  10286.             files anywhere  on the  search path  corresponding to the
  10287.             command name,  illustrating  pattern  matching  and  file
  10288.             system tests.
  10289.  
  10290.                 
  10291.                 proc whereis(name)
  10292.                   local i, j
  10293.                   if (name =~ "*.*") then
  10294.                      foreach i ($path)
  10295.                         if (i =~ "*\") then
  10296.                            if (-e $i$name) echo $i$name
  10297.                         else
  10298.                            if (-e $i\$name) echo $i\$name
  10299.                         end
  10300.                      end
  10301.                   else
  10302.                      foreach i ($path)
  10303.                         if (i =~ "*\") then
  10304.                            foreach j (.csh .exe .com .cmd)
  10305.                               if (-e $i$name$j) echo $i$name$j
  10306.                            end
  10307.                         else
  10308.                            foreach j (.csh .exe .com .cmd)
  10309.                               if (-e $i\$name$j) echo $i\$name$j
  10310.                            end
  10311.                         end
  10312.                      end
  10313.                   end
  10314.                 end
  10315.                 
  10316.                 whereis $argv
  10317.  
  10318.             Invoked as:
  10319.  
  10320.                 whereis ls
  10321.  
  10322.             It would print:
  10323.  
  10324.                 c:\os2\bin\ls.exe
  10325.  
  10326.             ls.exe is the file directory lister.  Invoked as:
  10327.  
  10328.                 time ls -l `whereis more`
  10329.  
  10330.             It would  show the  two versions of more.  (Our more ``is
  10331.             less filling and tastes better.'')
  10332.  
  10333.                 ---A-  Mar 20  8:00   20123  c:\os2\hamilton\more.exe
  10334.                 ---A-  Oct 26 12:00   31658  c:\os2\ibm\more.com
  10335.                 0:00:00.97
  10336.  
  10337.  
  10338.  
  10339.  
  10340.                                      Page 160
  10341.  
  10342.                                                                      Examples
  10343.  
  10344.  
  10345.             
  10346.  
  10347.  
  10348.                                 Samples Directory
  10349.  
  10350.  
  10351.                The sample  C programs  and C  shell  scripts  in  the
  10352.             samples directory  are  meant  to  help  you  install  or
  10353.             experiment with  Hamilton C shell.  Deliberately, they're
  10354.             relatively trivial.  All were created assuming TABS=3.
  10355.  
  10356.             args.c         A simple  C program  that prints  out  the
  10357.                            *argv[]     (argument)     and     *envp[]
  10358.                            (environmental variable)  arrays.   Notice
  10359.                            that wildcarding,  variable substitutions,
  10360.                            quoting and command substitutions are done
  10361.                            before the  C program  is started.  If you
  10362.                            do a  lot of  wildcarding, you  can create
  10363.                            and pass VERY long parameter lists (up 64K
  10364.                            characters on  OS/2 or  32K on  NT.)   Try
  10365.                            some of these commands:
  10366.  
  10367.                                 % args "ho"w 'no'w
  10368.                                 % args "$cwd" '$cwd'
  10369.                                 % args * "*" '*'
  10370.                                 % args `whereis more`
  10371.                                 % args '`whereis more`'
  10372.                                 % args * *\* *\*\* | more
  10373.  
  10374.             bits.csh       A  simple   self-loading  procedure   that
  10375.                            calculates the  minimum bits  required  to
  10376.                            represent the  argument it's  passed as  a
  10377.                            binary integer.
  10378.  
  10379.             blksize.c      A simple  C program that reads from Stdin,
  10380.                            copying to  Stdout,  using  the  specified
  10381.                            blocksize.   This program can be useful to
  10382.                            read  or  write  tape  devices  that  only
  10383.                            support   certain   blocksizes.      (Only
  10384.                            supplied with the Windows NT version.)
  10385.  
  10386.             bumpdate.csh   Print the date n number of days forward or
  10387.                            backward from  a given  date.  If only the
  10388.                            bump  value  is  given,  today's  date  is
  10389.                            bumped.
  10390.  
  10391.             caldate.csh    Print the  date corresponding  to a  given
  10392.                            Julian day.
  10393.  
  10394.             calendar.csh   A C  shell script  for  printing  out  the
  10395.                            calendar for any given month, highlighting
  10396.                            the current  date.   If no  date is given,
  10397.                            this month's calendar is printed.
  10398.  
  10399.  
  10400.  
  10401.  
  10402.                                      Page 161
  10403.  
  10404.      Examples
  10405.  
  10406.  
  10407.             colors.csh     Instructions and  examples on  customizing
  10408.                            the screen colors.
  10409.  
  10410.             cl.csh         On NT  only, run  the compiler  and linker
  10411.                            for an  NT program.  Avoids having to fool
  10412.                            with a  make file  just to  compile hello,
  10413.                            world.  Works pretty much just like the cl
  10414.                            command on DOS would.
  10415.  
  10416.             deltaday.csh   Print the  number of  days separating  two
  10417.                            dates.   If only  one date  is given,  the
  10418.                            difference between  it and today's date is
  10419.                            returned.
  10420.  
  10421.             dumpenv.c      This C  program writes out the environment
  10422.                            it's  passed   in  the   form  of   setenv
  10423.                            commands.  If you're installing Hamilton C
  10424.                            shell for  the first  time, dumpenv  is  a
  10425.                            convenient    way    to    snapshot    the
  10426.                            environmental variables  you've been using
  10427.                            with cmd.exe  in a  form you can append to
  10428.                            your login.csh file.
  10429.  
  10430.             duplicat.csh   Look for  duplicate files  anywhere  in  a
  10431.                            directory tree.
  10432.  
  10433.             easter.csh     A C  shell  script  that  calculates  when
  10434.                            Easter will  occur in  any given year.  If
  10435.                            no year  is given,  the  current  year  is
  10436.                            assumed.
  10437.  
  10438.             factor.csh     The simple  factor C shell script shown in
  10439.                            the User  Guide.  It's intended to show to
  10440.                            show the  use of  recursion,  expressions,
  10441.                            and a self-loading procedure.
  10442.  
  10443.             finance.csh    Another C  shell script showing expression
  10444.                            evaluation.   This  defines  a  number  of
  10445.                            routines   for    calculating    financial
  10446.                            conversion factors,  e.g., from present to
  10447.                            future value.
  10448.  
  10449.             getprio.c      This C  program (supplied  with  the  OS/2
  10450.                            version)   retrieves    and   prints   its
  10451.                            scheduling  priority,   demonstrating  the
  10452.                            effect of  using the eval command to run a
  10453.                            command at  a higher  or  lower  priority.
  10454.                            Try these examples:
  10455.  
  10456.                                 % getprio
  10457.                                 % eval -i getprio
  10458.                                 % eval +20 (getprio; eval +20
  10459.                                 getprio; getprio); getprio
  10460.  
  10461.  
  10462.  
  10463.  
  10464.                                      Page 162
  10465.  
  10466.                                                                      Examples
  10467.  
  10468.  
  10469.             julian.csh     Calculate the Julian day number (number of
  10470.                            days since  January 1,  4713 B.C.) for any
  10471.                            given date.   If you don't give a date, it
  10472.                            uses today's date.
  10473.  
  10474.             makecpgm.csh   A simple  C shell  script  showing  how  a
  10475.                            ``make'' function  might be written in the
  10476.                            C shell  language.   This one rebuilds any
  10477.                            .exe files  in the  current directory that
  10478.                            are older  than the  corresponding .c file
  10479.                            or any of the .h files.
  10480.  
  10481.             mcvisa.csh     A simple  C shell script that constructs a
  10482.                            special checksum  of a  credit card number
  10483.                            to tell if the card number is plausible or
  10484.                            not.   The checksum  used is  designed  to
  10485.                            catch transposed or incorrect digits.  Try
  10486.                            it on the cards in your wallet.
  10487.  
  10488.             member.csh     Test  whether   the  first  argument  word
  10489.                            appears somewhere in the list given by the
  10490.                            second argument.
  10491.  
  10492.             myecho.c       A variation  on the  built-in echo command
  10493.                            that prints  its *argv[]  (argument)  list
  10494.                            with quotes  around each  word it's passed
  10495.                            and tells  the total character count.  Try
  10496.                            these examples:
  10497.  
  10498.                                 % myecho now     is the
  10499.                                 % myecho "now     is" the
  10500.                                 % myecho `ls`
  10501.                                 % myecho `echo`
  10502.                                 % myecho `echo hello`
  10503.                                 % myecho * *\* *\*\* | more
  10504.  
  10505.             newfiles.csh   List all  the files  or directories in the
  10506.                            current directory that do not occur in the
  10507.                            specified directory.
  10508.  
  10509.             postage.csh    Calculate the  U.S.  first  class  postage
  10510.                            required for a given weight in ounces.
  10511.  
  10512.             rcode.c        A trivial C program that just prints, then
  10513.                            exits with  the return code value you pass
  10514.                            it.   You can  use this routine to see how
  10515.                            the status  variable is  set and also, how
  10516.                            the ``;,''  ``||''  and  ``&&''  statement
  10517.                            connectors work.  Try these examples:
  10518.  
  10519.                                 % rcode
  10520.                                 % calc status
  10521.                                 % rcode 1
  10522.                                 % calc status
  10523.  
  10524.  
  10525.  
  10526.                                      Page 163
  10527.  
  10528.      Examples
  10529.  
  10530.  
  10531.                                 % echo $status
  10532.                                 % echo status
  10533.                                 % rcode 2
  10534.                                 % calc status
  10535.                                 % rcode 0 || rcode 1
  10536.                                 % rcode 1 || rcode 2
  10537.                                 % rcode 0 && rcode 1
  10538.                                 % rcode 1 && rcode 2
  10539.                                 % rcode 0 ;  rcode 1
  10540.                                 % rcode 1 ;  rcode 2
  10541.  
  10542.                            rcode also  illustrates another  aspect of
  10543.                            return codes  to consider:   if  you use C
  10544.                            library stdio  (as rcode.c  does) and  you
  10545.                            exit with  a non-zero  return code,  stdio
  10546.                            thinks  it   was  an  error  and  discards
  10547.                            anything in  the stdio  buffers.   In  the
  10548.                            following example,  stdio  writes  to  the
  10549.                            screen are  unbuffered so  it  works;  but
  10550.                            pipes  are   buffered,  so   nothing  gets
  10551.                            written to it:
  10552.  
  10553.                                 % rcode 1
  10554.                                 1
  10555.                                 % rcode 1 | more
  10556.                                 --- End of file ---
  10557.                                 %
  10558.  
  10559.                            If you're writing an application that uses
  10560.                            return  codes,   you  should  remember  to
  10561.                            explicitly flush  the buffers  with  stdio
  10562.                            fflush() or use the kernel routines, e.g.,
  10563.                            DosWrite(), directly.
  10564.  
  10565.             sh_2_csh.csh   A script  for converting  Bourne  or  Korn
  10566.                            shell  scripts   into  Hamilton   C  shell
  10567.                            scripts  using   a  set   of  sed  scripts
  10568.                            contained in the sh_2_csh directory.
  10569.  
  10570.             sizeof.csh     A short C shell script that calculates and
  10571.                            prints the  cumulative size  of any number
  10572.                            of files or directories.
  10573.  
  10574.             ts.csh         A  C   shell  script   that  searches  for
  10575.                            occurrences of  a simple string in all the
  10576.                            files with a given extension anywhere in a
  10577.                            directory tree.
  10578.  
  10579.             viopaste.c     A short  C program (supplied with the OS/2
  10580.                            version)  to   enable   pasting   into   a
  10581.                            Presentation  Manager  text  window  under
  10582.                            OS/2 1.2 or 1.3.
  10583.  
  10584.  
  10585.  
  10586.  
  10587.  
  10588.                                      Page 164
  10589.  
  10590.                                                                      Examples
  10591.  
  10592.  
  10593.             weekday.csh    Print the day of the week corresponding to
  10594.                            any given date.
  10595.  
  10596.             winerror.csh   Print the Win32 message corresponding to a
  10597.                            given error code.  (Only supplied with the
  10598.                            Windows NT version.)
  10599.  
  10600.  
  10601.  
  10602.  
  10603.  
  10604.  
  10605.  
  10606.  
  10607.  
  10608.  
  10609.  
  10610.  
  10611.  
  10612.  
  10613.  
  10614.  
  10615.  
  10616.  
  10617.  
  10618.  
  10619.  
  10620.  
  10621.  
  10622.  
  10623.  
  10624.  
  10625.  
  10626.  
  10627.  
  10628.  
  10629.  
  10630.  
  10631.  
  10632.  
  10633.  
  10634.  
  10635.  
  10636.  
  10637.  
  10638.  
  10639.  
  10640.  
  10641.  
  10642.  
  10643.  
  10644.  
  10645.  
  10646.  
  10647.  
  10648.  
  10649.  
  10650.                                      Page 165
  10651.  
  10652.      Examples
  10653.  
  10654.  
  10655.  
  10656.                                         
  10657.  
  10658.  
  10659.  
  10660.  
  10661.  
  10662.  
  10663.  
  10664.  
  10665.  
  10666.  
  10667.  
  10668.  
  10669.  
  10670.  
  10671.  
  10672.  
  10673.  
  10674.  
  10675.  
  10676.  
  10677.  
  10678.  
  10679.  
  10680.  
  10681.  
  10682.  
  10683.  
  10684.  
  10685.  
  10686.  
  10687.  
  10688.  
  10689.  
  10690.  
  10691.  
  10692.  
  10693.  
  10694.  
  10695.  
  10696.  
  10697.  
  10698.  
  10699.  
  10700.  
  10701.  
  10702.  
  10703.  
  10704.  
  10705.  
  10706.  
  10707.  
  10708.  
  10709.  
  10710.  
  10711.  
  10712.                                      Page 166
  10713.  
  10714.                                                                 Compatibility
  10715.  
  10716.  
  10717.             
  10718.  
  10719.  
  10720.                                Compatibility Guide
  10721.  
  10722.  
  10723.             This section details the specific differences between the
  10724.             Hamilton C shell and the original UNIX C shell+.  It also
  10725.             describes the  Hamilton C  shell's Berkeley compatibility
  10726.             mode, used for running Berkeley C shell scripts.
  10727.  
  10728.  
  10729.  
  10730.             Berkeley 4.3 Buglist problems have been fixed.
  10731.  
  10732.             1.   Shell procedures  have been  provided and the clumsy
  10733.                  argument mechanism for aliases has been dropped.
  10734.  
  10735.             2.   Commands  typed   within  loops   or  other  control
  10736.                  structures are properly added to the history list.
  10737.  
  10738.             3.   Control structures  are recursively parsed, allowing
  10739.                  piping between them.  For example:
  10740.  
  10741.                       foreach i (a b c) echo $a; end | wc
  10742.  
  10743.                  properly displays
  10744.  
  10745.                               3        3       12
  10746.  
  10747.             4.   Any of  the `:' editing modifiers can be used on any
  10748.                  substitution.   Also,  a  space  inside  the  search
  10749.                  string in  a ``:s/.../.../''  command will match the
  10750.                  space between  two words.  In the UNIX C shell, only
  10751.                  certain modifiers  could be  used on a given type of
  10752.                  substitution and  it is  not possible  to perform  a
  10753.                  search/replace that crossed word boundaries.
  10754.  
  10755.  
  10756.  
  10757.             The language has been regularized.
  10758.  
  10759.             1.   The set,  setenv and  alias commands will now accept
  10760.                  the same  basic syntax.   The  UNIX C  shell  had  a
  10761.                  number of anomalies:  an `=' sign was required for a
  10762.                  set but  not for  setenv and alias; parenthesis were
  10763.                  required around  a word  list for  a set but not for
  10764.                  setenv and  alias; the set statement ignored all but
  10765.                  the first argument word but alias would not, etc.
  10766.             ____________________
  10767.             + The references used for comparison are the Berkeley 4.3
  10768.               Unix User's  Manual:   Reference Guide  (University  of
  10769.               California, 1986)  and The  UNIX C Shell Field Guide by
  10770.               Gail and Paul Anderson (Prentice-Hall, 1986.)
  10771.  
  10772.  
  10773.  
  10774.                                      Page 167
  10775.  
  10776.      Compatibility
  10777.  
  10778.  
  10779.             2.   Variables or  word lists are always indexed counting
  10780.                  the first  word as  element zero.   The UNIX C shell
  10781.                  counted from zero when indexing with ``:n'' notation
  10782.                  but from  one when  using ``[n]'' notation.  argv[0]
  10783.                  is the  first argument  word, not  the name  of  the
  10784.                  shell script being executed.  The name of the script
  10785.                  is kept in the local variable $scriptname.  This can
  10786.                  be overridden  by setting the inheritable per-thread
  10787.                  variable bsdargv = 1, causing argv[0] to be the name
  10788.                  of the script.
  10789.  
  10790.             3.   In keeping  with the  desire to  consistently  index
  10791.                  from zero, the last command entered into the history
  10792.                  list, ``!!'',  is considered  the 0-th element; ``!-
  10793.                  1'' is  the line  before  it.    The  UNIX  C  shell
  10794.                  considered  these  to  be  the  same.    A  built-in
  10795.                  variable, bsdhistory,  is provided  for those  whose
  10796.                  fingers prefer  the Berkeley  numbering  convention:
  10797.                  if you  set bsdhistory  = 1,  ``!!'' and ``!-1'' are
  10798.                  the same.
  10799.  
  10800.             4.   Where an  expression is  expected, conventional high
  10801.                  level language syntax is now acceptable.  The UNIX C
  10802.                  shell  required   spaces   around   any   expression
  10803.                  operators, a  variable reference  required a  `$' to
  10804.                  introduce it,  parenthesis were  required  to  avoid
  10805.                  confusing ``less  than'' with  i/o redirection, etc.
  10806.                  What had to be typed as
  10807.  
  10808.                       @ i = ($j + 3 * $k < 10)
  10809.  
  10810.                  under the  UNIX  C  shell  can  now  be  typed  (for
  10811.                  example) as
  10812.  
  10813.                       @ i=j+3*k<10
  10814.  
  10815.                  (The original  UNIX C  shell  expression  syntax  is
  10816.                  still entirely  acceptable and  will  still  produce
  10817.                  correct results.)
  10818.  
  10819.             5.   Inside a  ``[...]'' array  index, the  shell  always
  10820.                  looks for an expression, never an editing-style word
  10821.                  select.   Syntax and  keying rules  are the  same as
  10822.                  with any expression.
  10823.  
  10824.             6.   The case  statement now  accepts an expression to be
  10825.                  matched rather  than only  a pattern.  (To specify a
  10826.                  static pattern, enclose it in quotes.)  To determine
  10827.                  a match  against a  case clause, the case expression
  10828.                  is evaluated, converted to a string and then used as
  10829.                  a pattern to compare against the switch value.
  10830.  
  10831.             7.   The various  different end  statements used  by  the
  10832.                  UNIX C  shell,  end,  endif  and  endsw,  have  been
  10833.  
  10834.  
  10835.  
  10836.                                      Page 168
  10837.  
  10838.                                                                 Compatibility
  10839.  
  10840.  
  10841.                  replaced by  a single end statement.  Similarly, the
  10842.                  two break  statements, break  and breaksw, have been
  10843.                  replaced  with   a  single  break  statement.    For
  10844.                  compatibility with  existing scripts,  the  obsolete
  10845.                  keywords are implemented as aliases.
  10846.  
  10847.             8.   Since Hamilton  C shell  is free  format (i.e.,  new
  10848.                  statements need not begin on a new line), the UNIX C
  10849.                  shell convention  of chaining  if statements  with a
  10850.                  single end  if the  else and if are on the same line
  10851.                  isn't possible.   Instead,  an elif keyword has been
  10852.                  added.
  10853.  
  10854.             9.   The obscure use of several break statements in a row
  10855.                  on a  single line  to break out of several levels of
  10856.                  control statements  at once has been eliminated.  In
  10857.                  its place, a label may be specified as an operand to
  10858.                  indicate the control structure to ``break'' out of.
  10859.  
  10860.  
  10861.  
  10862.  
  10863.  
  10864.  
  10865.  
  10866.  
  10867.  
  10868.  
  10869.  
  10870.  
  10871.  
  10872.  
  10873.  
  10874.  
  10875.  
  10876.  
  10877.  
  10878.  
  10879.  
  10880.  
  10881.  
  10882.  
  10883.  
  10884.  
  10885.  
  10886.  
  10887.  
  10888.  
  10889.  
  10890.  
  10891.  
  10892.  
  10893.  
  10894.  
  10895.  
  10896.  
  10897.  
  10898.                                      Page 169
  10899.  
  10900.      Compatibility
  10901.  
  10902.  
  10903.             Modern compiler technology has been employed.
  10904.  
  10905.                  Statements are  parsed and compiled into an internal
  10906.             form before  any substitutions  or  other  evaluation  is
  10907.             attempted.     This  offers   an   enormous   performance
  10908.             improvement, particularly  when  iteration  is  involved.
  10909.             (The UNIX  C shell  would actually reparse each statement
  10910.             inside a foreach loop each time through the loop.)
  10911.  
  10912.                  If command-  or variable-substitution creates any of
  10913.             the following  reserved  words  or  tokens,  the  special
  10914.             semantic meaning  will be lost since substitution is done
  10915.             after parsing of statement structure.  Instead, they will
  10916.             simply be  treated as  character strings.  These reserved
  10917.             words are:
  10918.  
  10919.               Introducing a clause in a structured statement:
  10920.  
  10921.                  alias     elif      if        setkey    unproc
  10922.                  break     else      local     source    unset
  10923.                  by        end       onintr    switch    unsetenv
  10924.                  calc      eval      proc      then      unsetkey
  10925.                  case      exit      repeat    time      until
  10926.                  continue  for       return    to        while
  10927.                  default   foreach   set       unalias   @
  10928.                  do        goto      setenv    unlocal
  10929.  
  10930.               Anywhere:
  10931.  
  10932.                            ( ) < > & | ;
  10933.  
  10934.               In an expression:
  10935.  
  10936.                            + - * / % =
  10937.  
  10938.                  Similarly, labels  cannot be  run-time evaluated  to
  10939.             see what  the  label  on  a  statement  is;  it  must  be
  10940.             evaluated when the statement is first parsed.
  10941.  
  10942.  
  10943.  
  10944.             Extensions:
  10945.  
  10946.             1.   Command line  editing with the arrow keys, etc., and
  10947.                  the setkey statements are new.
  10948.  
  10949.             2.   The procedure  mechanism, including the proc, unproc
  10950.                  and   return statements  and  the  various  built-in
  10951.                  procedures, is new.
  10952.  
  10953.             3.   Local variables and local and unlocal statements are
  10954.                  new.
  10955.  
  10956.  
  10957.  
  10958.  
  10959.  
  10960.                                      Page 170
  10961.  
  10962.                                                                 Compatibility
  10963.  
  10964.  
  10965.             4.   The use  of color highlighting to indicate exception
  10966.                  situations in filename or command completion is new.
  10967.  
  10968.             5.   The for  statement, providing numeric iteration, and
  10969.                  the calc  statement,  which  writes  the  result  of
  10970.                  expression evaluation to stdout, are new.
  10971.  
  10972.             6.   The ``**''  and ``**='' exponentiation operators are
  10973.                  new.
  10974.  
  10975.             7.   Floating point arithmetic is new.
  10976.  
  10977.             8.   The path  hashing mechanism  is  substantially  less
  10978.                  sensitive to  blindspots caused  by creating  a  new
  10979.                  executable in  one of  the path  directories and not
  10980.                  manually specifying  rehash.  The UNIX C shell would
  10981.                  not be able to find the new file; this shell makes a
  10982.                  second pass  through the  path directories  whenever
  10983.                  hashing fails,  looking for  this  sort  of  problem
  10984.                  before it reports failure.  If it finds a blindspot,
  10985.                  it automatically rehashes that directory.
  10986.  
  10987.             9.   History references  are allowed  in the  inline text
  10988.                  supplied with  the ``<<'' i/o redirection mechanism.
  10989.                  Also, the  inline text  is remembered in the history
  10990.                  list, each  line as  a single  word. This avoids the
  10991.                  user having  to remember  and retype the inline text
  10992.                  any time  one of  these statements  is recalled from
  10993.                  the history  list or  if the  history list is dumped
  10994.                  for use in a script file.
  10995.  
  10996.             10.  Exclusion ranges, e.g., ``[^a-z],'' can be used in a
  10997.                  wildcard pattern.
  10998.  
  10999.             11.  Escape sequences to encode special characters (e.g.,
  11000.                  ``^a'' for audible bell or ``^b'' for backspace) are
  11001.                  recognized in the arguments to any command, not just
  11002.                  echo.   Because this  processing is  internal to the
  11003.                  shell, it  is not necessary to type two escapes in a
  11004.                  row to  access this  feature.   (Refer to  the  echo
  11005.                  command help screen for a complete list.)
  11006.  
  11007.             12.  Argument lists passed to a child process can be much
  11008.                  larger than  are allowed  under UNIX.   The  UNIX  C
  11009.                  shell  allows  only  roughly  6K  characters  to  be
  11010.                  passed, depending  on the revision level; this shell
  11011.                  allows up  to 64K  to be  passed to  a child process
  11012.                  under OS/2  or 32K  under NT,  the kernel  limits on
  11013.                  these systems.  There is no command line limit to an
  11014.                  internal  command   such  as   echo.    This  is  of
  11015.                  particular  importance   when  wildcarding  is  used
  11016.                  heavily.
  11017.  
  11018.  
  11019.  
  11020.  
  11021.  
  11022.                                      Page 171
  11023.  
  11024.      Compatibility
  11025.  
  11026.  
  11027.             13.  Quoted strings are shown in the history list exactly
  11028.                  as they  would have to be typed.  (The Berkeley UNIX
  11029.                  C shell  marked a character as quoted by setting its
  11030.                  high-order bit; setting aside portability issues, it
  11031.                  had the  side-effect of  not being  visible  in  the
  11032.                  history list.)
  11033.  
  11034.             14.  Parentheses in  an argument  list to  an  executable
  11035.                  statement need  not be  escaped, so long as they are
  11036.                  matched.  Semicolons, i/o redirection symbols, etc.,
  11037.                  inside these  parentheses are treated simply as text
  11038.                  and are passed straight through to the application.
  11039.  
  11040.             15.  The  ``:b''   (base)  and   ``:#''  (count)  editing
  11041.                  operators are new.
  11042.  
  11043.             16.  The   indefinite   directory   wildcard   construct,
  11044.                  ``...'', is new.
  11045.  
  11046.  
  11047.  
  11048.             Restrictions and unimplemented features:
  11049.  
  11050.             1.   Job control  is not  supported.   Job control is not
  11051.                  currently feasible  under Windows NT or OS/2 because
  11052.                  once one thread from any process within a window has
  11053.                  started to  read the  keyboard, the  read can not be
  11054.                  interrupted.  (Fortunately, one can always open more
  11055.                  windows.)
  11056.  
  11057.             2.   The use  of ``\!'' inside a prompt string to get the
  11058.                  statement number  is  not  supported.    Use  $@  or
  11059.                  $stmtnumber instead.
  11060.  
  11061.             3.   The following  statements, all  fairly  specific  to
  11062.                  UNIX,  are  not  supported:    alloc,  glob,  limit,
  11063.                  notify, stop.
  11064.  
  11065.             4.   The comment  character, #,  must be followed by some
  11066.                  white space  to be  considered the  start of a valid
  11067.                  comment.   (That's because # is a legal character in
  11068.                  a filename under both NT and OS/2.)
  11069.  
  11070.  
  11071.  
  11072.             Adaptation for OS/2 and Windows NT:
  11073.  
  11074.             1.   OS/2 and  Win32 NT do not provide a fork( ) call for
  11075.                  inexpensively  cloning  an  independent  copy  of  a
  11076.                  running process,  complete  with  its  own  separate
  11077.                  memory image.  Instead, OS/2 and NT provide a faster
  11078.                  alternative  called   threads,  which   creates   an
  11079.                  separately scheduled  flow of  control  through  the
  11080.                  memory space of a single process.
  11081.  
  11082.  
  11083.  
  11084.                                      Page 172
  11085.  
  11086.                                                                 Compatibility
  11087.  
  11088.  
  11089.                  In general, the Hamilton C shell spawns a new thread
  11090.                  anywhere the Berkeley UNIX C shell would have used a
  11091.                  process.   Using a  new  thread  instead  of  a  new
  11092.                  invocation of  the Hamilton  C shell  saves  over  a
  11093.                  second each  time.   Individual threads manage their
  11094.                  own notions  of current directories and current disk
  11095.                  and certain  per-thread variables but the dictionary
  11096.                  of aliases,  procedures and most variables is shared
  11097.                  among all threads.
  11098.  
  11099.                  The result is that background activities and C shell
  11100.                  scripts can  change  variables,  define  procedures,
  11101.                  etc., for  use by  the other  threads.  For example,
  11102.                  procedures can  be written  as self-loading scripts.
  11103.                  (See the whereis.csh file for an example.)
  11104.  
  11105.             2.   OS/2 and  NT conventions  are followed:   either the
  11106.                  ``\'' or  the ``/''  characters can  be  used  in  a
  11107.                  filename; the ``^'' character is normally the escape
  11108.                  character;  directories   in  the  PATH  environment
  11109.                  variable are separated by semicolons, etc.
  11110.  
  11111.             3.   Labels cannot be a single letter.  (This is to avoid
  11112.                  confusing the  drive letter  in the  pathname of  an
  11113.                  executable file as a label.)
  11114.  
  11115.             4.   Since  OS/2   and  most   NT  filenames   are  case-
  11116.                  insensitive, they  are routinely translated to lower
  11117.                  case  for   better  readability.     (This   can  be
  11118.                  overridden using the MIXEDCASEDRIVES variable.)
  11119.  
  11120.             5.   Executable files  are recognized by their extension.
  11121.                  The following  extensions are  recognized  (in  this
  11122.                  order):   .csh, .exe,  .com, .cmd, .bat.  .csh files
  11123.                  are interpreted  as C shell scripts by a new thread,
  11124.                  .exe and .com files are executed with the DosExecPgm
  11125.                  and DosStartSession  kernel functions  under OS/2 or
  11126.                  with the  CreateProcess kernel  function  under  NT,
  11127.                  .cmd  files  are  interpreted  by  a  child  process
  11128.                  running cmd.exe,  and .bat  files are  passed  to  a
  11129.                  Virtual DOS  machine (VDM)  under  OS/2  2.x  or  to
  11130.                  cmd.exe under NT.
  11131.  
  11132.             6.   PROMPT1 and  PROMPT2 variables  are used  to set the
  11133.                  primary and  secondary prompt  strings.   Using  the
  11134.                  UNIX C  shell variable  PROMPT would have conflicted
  11135.                  with cmd.exe's  use of  the same name and would have
  11136.                  meant a  nonsense  prompt  string  any  time  either
  11137.                  command processor was invoked by other.
  11138.  
  11139.             7.   The following  startup  or  other  files  have  been
  11140.                  renamed to  be more  consistent  with  OS/2  and  NT
  11141.                  filename conventions:   ~/.cshrc  as  ~\startup.csh;
  11142.                  ~/.login as  ~\login.csh; ~/.logout as ~\logout.csh;
  11143.  
  11144.  
  11145.  
  11146.                                      Page 173
  11147.  
  11148.      Compatibility
  11149.  
  11150.  
  11151.                  and ~/.history  as ~\history.csh.   The  ~\login.csh
  11152.                  file  is   read  before,   rather  than   after  the
  11153.                  ~\startup.csh file.   When  starting the  shell as a
  11154.                  new session,  very little  environmental information
  11155.                  may be  passed; the  login.csh is  more usefully the
  11156.                  first file  read in this situation.  When starting a
  11157.                  subshell,  either   from  csh.exe  or  cmd.exe,  the
  11158.                  environment is presumably already set up.
  11159.  
  11160.  
  11161.  
  11162.             Berkeley Compatibility Mode:
  11163.  
  11164.                  Berkeley Compatibility  Mode provides  fairly strict
  11165.             compatibility with  the original  BSD C shell.  Triggered
  11166.             by trying  to run a script that starts with #!/bin/csh or
  11167.             interactively if the shell is invoked with the -B option,
  11168.             it causes  the C  shell to  process statements  in a more
  11169.             fully Berkeley-compatible  fashion.  (Scripts that do not
  11170.             start with  #!/bin/csh will  still be processed according
  11171.             to Hamilton  C shell rules, even if the -B option is used
  11172.             to  request  Berkeley  compatibility  interactively.)  In
  11173.             compatibility mode:
  11174.  
  11175.             1.   The status  variable will  reflect the  return  code
  11176.                  from  the  rightmost  stage  of  a  pipeline.    The
  11177.                  tailstatus variable will be ignored.
  11178.  
  11179.             2.   All the  shell variables will be snapshotted and all
  11180.                  new variables made local to the thread.
  11181.  
  11182.             3.   Berkeley-style $var[...]  indexing notation  will be
  11183.                  used,  where  the  indexing  is  by  word  selection
  11184.                  operators (like the :-editing operators) rather than
  11185.                  by expression.
  11186.  
  11187.             4.   All variable  arrays (except  argv) will  start with
  11188.                  element 1.  Accessing element 0 will give a null.
  11189.  
  11190.             5.   $0 or  $argv[0] will  be the scriptname.  $argv will
  11191.                  be the  rest of  the argument  vector.   The bsdargv
  11192.                  variable will be ignored.
  11193.  
  11194.             6.   The #  character will  not need  to be  followed  by
  11195.                  white space to be considered the start of a comment.
  11196.  
  11197.             7.   The patterns  in a  case test (inside a switch) will
  11198.                  be strings  and need  not  be  quoted,  rather  than
  11199.                  arbitrary expressions.   Also,  the switch  value is
  11200.                  evaluated as  a wordlist  which may contain variable
  11201.                  or command  substitutions  and  wildcards  and  then
  11202.                  rendered as a string.
  11203.  
  11204.  
  11205.  
  11206.  
  11207.  
  11208.                                      Page 174
  11209.  
  11210.                                                                 Compatibility
  11211.  
  11212.  
  11213.             8.   endif and  endsw will  be predefined aliases for end
  11214.                  (but  only   when   closing   an   if   or   switch,
  11215.                  respectively).   breaksw will be a pre-defined alias
  11216.                  for break.
  11217.  
  11218.             9.   ``set foo''  and ``setenv  foo'' will  set foo  to a
  11219.                  null string, not dump its value.
  11220.  
  11221.             10.  / and /= will perform integer division.
  11222.  
  11223.             11.  The right  operand of the =~ and !~ pattern matching
  11224.                  operators will  be taken as a word which may contain
  11225.                  wildcards.
  11226.  
  11227.             12.  In an  expression, a  variable name must be preceded
  11228.                  by $.   If  it isn't,  it'll be  taken as  a literal
  11229.                  string.
  11230.  
  11231.                  These changes  should  allow  most  scripts  to  run
  11232.             without problems.   However,  there will  still be  a few
  11233.             differences:
  11234.  
  11235.             1.   The escape character will still be controlled by the
  11236.                  escapesym  variable  (shared  across  all  threads),
  11237.                  which defaults to ^, not \.
  11238.  
  11239.             2.   Environmental  variables   will  still   be  shared.
  11240.                  Changing them  in a  script will change them as seen
  11241.                  by the parent.
  11242.  
  11243.             3.   The special  meaning of  several break statements on
  11244.                  one line will not be supported.
  11245.  
  11246.             4.   unset and unsetenv still do not accept patterns.
  11247.  
  11248.             5.   The following  commands are not supported: bg, exec,
  11249.                  fg, glob,  jobs, limit, nice (but eval gives similar
  11250.                  functionality),  nohup,   notify,   stop,   suspend,
  11251.                  unlimit and %job.
  11252.  
  11253.  
  11254.  
  11255.  
  11256.  
  11257.  
  11258.  
  11259.  
  11260.  
  11261.  
  11262.  
  11263.  
  11264.  
  11265.  
  11266.  
  11267.  
  11268.  
  11269.  
  11270.                                      Page 175
  11271.  
  11272.      Compatibility
  11273.  
  11274.  
  11275.             
  11276.  
  11277.  
  11278.  
  11279.  
  11280.  
  11281.  
  11282.  
  11283.  
  11284.  
  11285.  
  11286.  
  11287.  
  11288.  
  11289.  
  11290.  
  11291.  
  11292.  
  11293.  
  11294.  
  11295.  
  11296.  
  11297.  
  11298.  
  11299.  
  11300.  
  11301.  
  11302.  
  11303.  
  11304.  
  11305.  
  11306.  
  11307.  
  11308.  
  11309.  
  11310.  
  11311.  
  11312.  
  11313.  
  11314.  
  11315.  
  11316.  
  11317.  
  11318.  
  11319.  
  11320.  
  11321.  
  11322.  
  11323.  
  11324.  
  11325.  
  11326.  
  11327.  
  11328.  
  11329.  
  11330.  
  11331.  
  11332.                                      Page 176
  11333.  
  11334.                                                            Language Reference
  11335.  
  11336.  
  11337.             
  11338.  
  11339.  
  11340.                                Language Reference
  11341.  
  11342.  
  11343.  
  11344.  
  11345.             Basic Statements:
  11346.  
  11347.                  Same as cmd.exe:  a file reference + arguments.
  11348.  
  11349.                       Examples: cl -AS -G2 -Zi hello.c
  11350.                                 cp hello.exe c:\os2\bin
  11351.  
  11352.                  Hamilton C  shell maintains  a hash  structure which
  11353.                  allows it  to quickly  search for  a suitable  .csh,
  11354.                  .exe, .com,  .cmd or  (on OS/2  2.x or NT) .bat file
  11355.                  (in that  order) in  each of  as many  as  256  path
  11356.                  directories.   Wildcarding  is  done  by  the  shell
  11357.                  before invoking the child.  Under OS/2, up to 64K of
  11358.                  environmental and  64K of command-line argument data
  11359.                  can be  passed to  a child  process; under NT, up to
  11360.                  32K of  command-line data  can be passed.  These are
  11361.                  the limits of the kernels, not the C shell; there is
  11362.                  no limit  on overall  command line  length in  the C
  11363.                  shell itself.
  11364.  
  11365.  
  11366.             Condition-Testing:
  11367.  
  11368.                  Hamilton  C   shell  provides  both  if  and  switch
  11369.                  constructs.   The if  statement comes  in both short
  11370.                  and long  forms.   The long form uses a then keyword
  11371.                  and allows an optional else clause.  The short form,
  11372.                  which must  be typed on one line, dispenses with the
  11373.                  then keyword  and accepts  a single  statement to be
  11374.                  executed if the condition is satisfied.
  11375.  
  11376.                       if ( <expr> ) then
  11377.                         <statement_list>
  11378.                       else
  11379.                         <statement_list>
  11380.                       end
  11381.  
  11382.                       if ( <expr> ) then
  11383.                         <statement_list>
  11384.                       end
  11385.  
  11386.                       if ( <expr> ) <statement>
  11387.  
  11388.                  Where an expression is expected, a conventional high
  11389.                  level language  syntax is  accepted:    e.g.,  names
  11390.  
  11391.  
  11392.  
  11393.  
  11394.                                      Page 177
  11395.  
  11396.      Language Reference
  11397.  
  11398.  
  11399.                  refer to variables, `*' means multiply, not wildcard
  11400.                  and `>' means greater than, not i/o redirection.
  11401.  
  11402.  
  11403.  
  11404.  
  11405.  
  11406.  
  11407.  
  11408.  
  11409.  
  11410.  
  11411.  
  11412.  
  11413.  
  11414.  
  11415.  
  11416.  
  11417.  
  11418.  
  11419.  
  11420.  
  11421.  
  11422.  
  11423.  
  11424.  
  11425.  
  11426.  
  11427.  
  11428.  
  11429.  
  11430.  
  11431.  
  11432.  
  11433.  
  11434.  
  11435.  
  11436.  
  11437.  
  11438.  
  11439.  
  11440.  
  11441.  
  11442.  
  11443.  
  11444.  
  11445.  
  11446.  
  11447.  
  11448.  
  11449.  
  11450.  
  11451.  
  11452.  
  11453.  
  11454.  
  11455.  
  11456.                                      Page 178
  11457.  
  11458.                                                            Language Reference
  11459.  
  11460.  
  11461.             
  11462.             
  11463.  
  11464.                  if statements  can also  be chained  using the  elif
  11465.                  keyword.   The last  if in the chain may be either a
  11466.                  short- or a long-form if statement.
  11467.  
  11468.                       if ( <expr> ) then
  11469.                         <statement_list>
  11470.                       elif ( <expr> ) then
  11471.                         <statement_list>
  11472.                       else
  11473.                         <statement_list>
  11474.                       end
  11475.  
  11476.                       if ( <expr> ) then
  11477.                         <statement_list>
  11478.                       elif ( <expr> ) then
  11479.                         <statement_list>
  11480.                       end
  11481.  
  11482.                       if ( <expr> ) then
  11483.                         <statement_list>
  11484.                       elif ( <expr> )  <statement>
  11485.  
  11486.                  In a  switch statement,  expressions are compared by
  11487.                  pattern match:   the case expression can be a string
  11488.                  with wildcard characters.  Comparisons are made down
  11489.                  the list  of alternatives  until one  matches.   All
  11490.                  following statements  are executed  until a break is
  11491.                  encountered.   A default  clause is  optional but is
  11492.                  always satisfied if no other case matches.
  11493.  
  11494.                       switch ( <expr> )
  11495.                         case <expr> :
  11496.                            <statement_list>
  11497.                         case <expr> :
  11498.                            <statement_list>
  11499.                         default :
  11500.                            <statement_list>
  11501.                       end
  11502.  
  11503.  
  11504.  
  11505.  
  11506.  
  11507.  
  11508.  
  11509.  
  11510.  
  11511.  
  11512.  
  11513.  
  11514.  
  11515.  
  11516.  
  11517.  
  11518.                                      Page 179
  11519.  
  11520.      Language Reference
  11521.  
  11522.  
  11523.             
  11524.             
  11525.  
  11526.  
  11527.             Iteration:
  11528.  
  11529.                       foreach <name> ( <word list> )
  11530.                         <statement_list>
  11531.                       end
  11532.  
  11533.                       for <name> = <expr> [ to <expr> ] [ by <expr> ]
  11534.                       do
  11535.                         <statement_list>
  11536.                       end
  11537.  
  11538.                       while ( <expr> )
  11539.                         <statement_list>
  11540.                       end
  11541.  
  11542.                       repeat <number> <statement>
  11543.  
  11544.                       repeat
  11545.                         <statement_list>
  11546.                       until ( <expr> )
  11547.  
  11548.                  The foreach statement is intended for iteration over
  11549.                  a list  of words,  often specified  by  wildcarding.
  11550.                  The  for  statement  offers  the  more  conventional
  11551.                  numeric  iteration.     Multiple  iteration  ranges,
  11552.                  separated by  commas, can  be specified  on the  for
  11553.                  statement.
  11554.  
  11555.  
  11556.             Procedures:
  11557.  
  11558.                       proc <name> ( [ <namelist> ] )
  11559.                         <statement_list>
  11560.                          return [ <expr> ]
  11561.                       end
  11562.  
  11563.                       proc
  11564.  
  11565.                       unproc <namelist>
  11566.  
  11567.                  Procedures  defined   by  the   proc  statement  can
  11568.                  recursively call  other procedures.    They  can  be
  11569.                  referred  to  inside  an  expression  or  as  a  new
  11570.                  command, in which case any value returned is written
  11571.                  to stdout.   The  proc statement  with no  arguments
  11572.                  causes a  list of  the available  procedures  to  be
  11573.                  written.  The unproc statement allows a procedure to
  11574.                  be discarded.
  11575.  
  11576.  
  11577.  
  11578.  
  11579.  
  11580.                                      Page 180
  11581.  
  11582.                                                            Language Reference
  11583.  
  11584.  
  11585.             
  11586.             
  11587.  
  11588.  
  11589.             Aliases:
  11590.  
  11591.                       alias <name> [ = ] ( <word list> )
  11592.                       alias <name> [ = ] <word list>
  11593.  
  11594.                       alias
  11595.                       alias <name>
  11596.  
  11597.                       unalias <namelist>
  11598.  
  11599.                  Aliases can  be referred  to at  the beginning  of a
  11600.                  command and provide a quick, user-defined shorthand.
  11601.                  alias <name>  with no  arguments prints the value of
  11602.                  the name.   alias  without any  arguments prints the
  11603.                  values of all aliases.
  11604.  
  11605.  
  11606.             Variable and Expression Manipulation:
  11607.  
  11608.                       @ <expr>
  11609.                       calc <expr>
  11610.  
  11611.                  The @  and calc  statements will  each calculate the
  11612.                  value of  an expression;  the @  statement  does  it
  11613.                  silently while  the calc statement writes the result
  11614.                  to stdout.
  11615.  
  11616.                       set <named_ref> [ = ] ( <word list> )
  11617.                       set <named_ref> [ = ] <word list>
  11618.                       setenv <named_ref> [ = ] ( <word list> )
  11619.                       setenv <named_ref> [ = ] <word list>
  11620.                       shift [ <name> ]
  11621.  
  11622.                       set
  11623.                       set <name>
  11624.                       setenv
  11625.                       setenv <name>
  11626.  
  11627.                       unset <namelist>
  11628.                       unsetenv <namelist>
  11629.  
  11630.                  The set,  setenv  and  shift  statements  manipulate
  11631.                  variables as  words rather  than expressions.    set
  11632.                  defines a  set variable  that's shared  between  all
  11633.                  threads in  the  shell;  setenv  puts  it  into  the
  11634.                  environment and  inherited by  child processes.  set
  11635.                  or setenv  with no  operands prints  a list  of  all
  11636.                  defined variables  of  that  type.    set <name>  or
  11637.                  setenv <name> with  no arguments  print the value of
  11638.  
  11639.  
  11640.  
  11641.  
  11642.                                      Page 181
  11643.  
  11644.      Language Reference
  11645.  
  11646.  
  11647.                  the named  variable.   unset  or  unsetenv  let  you
  11648.                  discard a variable.
  11649.  
  11650.  
  11651.  
  11652.  
  11653.  
  11654.  
  11655.  
  11656.  
  11657.  
  11658.  
  11659.  
  11660.  
  11661.  
  11662.  
  11663.  
  11664.  
  11665.  
  11666.  
  11667.  
  11668.  
  11669.  
  11670.  
  11671.  
  11672.  
  11673.  
  11674.  
  11675.  
  11676.  
  11677.  
  11678.  
  11679.  
  11680.  
  11681.  
  11682.  
  11683.  
  11684.  
  11685.  
  11686.  
  11687.  
  11688.  
  11689.  
  11690.  
  11691.  
  11692.  
  11693.  
  11694.  
  11695.  
  11696.  
  11697.  
  11698.  
  11699.  
  11700.  
  11701.  
  11702.  
  11703.  
  11704.                                      Page 182
  11705.  
  11706.                                                            Language Reference
  11707.  
  11708.  
  11709.             
  11710.             
  11711.  
  11712.  
  11713.             Local Variables:
  11714.  
  11715.                  The local command lets you define a list of variable
  11716.                  names that you don't to share with other routines or
  11717.                  other processes  or threads  (except your  own child
  11718.                  threads).  When you define a local variable it hides
  11719.                  any previous  definition from  any  outer  statement
  11720.                  list.  (But you are not permitted to redefine any of
  11721.                  the built-in set or setenv variable names.)
  11722.  
  11723.                       local <namelist>
  11724.                       local
  11725.  
  11726.                  The <namelist>  should be  typed with commas between
  11727.                  the names.   When  you create  a new local variable,
  11728.                  its initial  value is  always a null string.  Typing
  11729.                  local with no operands reports the currently defined
  11730.                  and accessible local variables, if any.
  11731.  
  11732.                  When you  spawn a  child thread  either  implicitly,
  11733.                  e.g., to  run the  second or  following stage  of  a
  11734.                  pipeline or  explicitly, by  typing an  ampersand at
  11735.                  the end of a command to run it in the background all
  11736.                  your current  local variables  are  snapshotted  and
  11737.                  copied to the child.  If, following that, either the
  11738.                  parent or  the child  changes the  value of  any  of
  11739.                  these local variables, it affects only its own copy.
  11740.  
  11741.                  Local variables  are automatically discarded as soon
  11742.                  as execution  leaves the  statement nesting level in
  11743.                  which the  variable  was  created.    You  can  also
  11744.                  explicitly discard local variables using the unlocal
  11745.                  command.
  11746.  
  11747.                       unlocal <namelist>
  11748.  
  11749.                  In all other respects, local variables act just like
  11750.                  any other  variables, though  you may  find  they're
  11751.                  slightly faster  since the  shell  doesn't  need  to
  11752.                  semaphore its use of them.
  11753.  
  11754.  
  11755.  
  11756.  
  11757.  
  11758.  
  11759.  
  11760.  
  11761.  
  11762.  
  11763.  
  11764.  
  11765.  
  11766.                                      Page 183
  11767.  
  11768.      Language Reference
  11769.  
  11770.  
  11771.             
  11772.  
  11773.  
  11774.                                   Function Keys
  11775.  
  11776.  
  11777.  
  11778.  
  11779.             setkey command:
  11780.  
  11781.                  The setkey  command lets  you define a list of words
  11782.                  that should  be stuffed  back onto  the command-line
  11783.                  whenever you  press a  particular function key.  The
  11784.                  syntax is  exactly the  same as  used  in  the  set,
  11785.                  setenv and alias commands:
  11786.  
  11787.                       setkey <fkey> [ = ] ( <word list> )
  11788.                       setkey <fkey> [ = ] <word list>
  11789.  
  11790.                  where <fkey>  is any of the function keys f1 (or F1)
  11791.                  through f12 (or F12.)
  11792.  
  11793.                  Typing setkey  with no  operands reports the current
  11794.                  function  key   bindings,   if   any.      Also,   a
  11795.                  corresponding unsetkey  command lets you discard key
  11796.                  bindings:
  11797.  
  11798.                       setkey
  11799.                       unsetkey <fkeylist>
  11800.  
  11801.                  The <fkeylist>  should be  typed with commas between
  11802.                  the keys.  For example:
  11803.  
  11804.                       unsetkey f1, f2
  11805.  
  11806.  
  11807.             Using the Function Keys
  11808.  
  11809.  
  11810.               Key               Meaning                              
  11811.  
  11812.               <Fx>              Clear the command line, post the text
  11813.                                 bound to this key and execute the
  11814.                                 command.
  11815.  
  11816.               Alt-<Fx>          Insert the text bound to this key at
  11817.                                 the cursor location but don't execute
  11818.                                 it yet.
  11819.  
  11820.               Ctrl-<Fx>         Clear the command line and post the
  11821.                                 text bound to this key but don't
  11822.                                 execute it yet.
  11823.  
  11824.  
  11825.  
  11826.  
  11827.  
  11828.                                      Page 184
  11829.  
  11830.                                                            Language Reference
  11831.  
  11832.  
  11833.                  Since the  function key's bound text is written back
  11834.                  into the  command line  inside command  line editor,
  11835.                  the substitution happens ahead of any parsing of the
  11836.                  command line  into words  or  expansion  of  history
  11837.                  ``!...'' or ``%...'' references so it is possible to
  11838.                  meaningfully embed  these kinds  of references  into
  11839.                  the key binding.
  11840.  
  11841.  
  11842.  
  11843.  
  11844.  
  11845.  
  11846.  
  11847.  
  11848.  
  11849.  
  11850.  
  11851.  
  11852.  
  11853.  
  11854.  
  11855.  
  11856.  
  11857.  
  11858.  
  11859.  
  11860.  
  11861.  
  11862.  
  11863.  
  11864.  
  11865.  
  11866.  
  11867.  
  11868.  
  11869.  
  11870.  
  11871.  
  11872.  
  11873.  
  11874.  
  11875.  
  11876.  
  11877.  
  11878.  
  11879.  
  11880.  
  11881.  
  11882.  
  11883.  
  11884.  
  11885.  
  11886.  
  11887.  
  11888.  
  11889.  
  11890.                                      Page 185
  11891.  
  11892.      Language Reference
  11893.  
  11894.  
  11895.  
  11896.                             Miscellaneous Statements
  11897.  
  11898.  
  11899.               Statement                   Function                   
  11900.  
  11901.               <drive>:                    Change current drive.
  11902.  
  11903.               <label>:  <statement>       Define a label.
  11904.  
  11905.               ( <statement_list> )        Group a list of statements,
  11906.                                           saving and restoring the
  11907.                                           current directory during
  11908.                                           execution
  11909.  
  11910.               break [ <name> ]            Exit from the named or, by
  11911.                                           default, the innermost
  11912.                                           switch, foreach, for, while
  11913.                                           or repeat statement.
  11914.  
  11915.               continue [ <name> ]         Continue with the next
  11916.                                           iteration of the named or
  11917.                                           innermost foreach, for,
  11918.                                           while or repeat.
  11919.  
  11920.               exit [ <expr> ]             Exit from this thread or,
  11921.                                           if this is the main thread,
  11922.                                           from the C shell.
  11923.  
  11924.               goto <name>                 Continue at the labeled
  11925.                                           statement.
  11926.  
  11927.               onintr <statement>          Define the action to be
  11928.                                           taken if an interrupt is
  11929.                                           signaled.  Whatever's
  11930.                                           running is interrupted all
  11931.                                           the way back up to the
  11932.                                           block in which the onintr
  11933.                                           was defined.  That
  11934.                                           statement is run in the
  11935.                                           current thread and
  11936.                                           execution continues with
  11937.                                           the next statement in the
  11938.                                           block where the onintr was
  11939.                                           defined.  When execution
  11940.                                           leaves a block in which an
  11941.                                           onintr is defined, the
  11942.                                           previous onintr (if any)
  11943.                                           again takes effect.  To
  11944.                                           ignore or defer interrupts,
  11945.                                           use the irqmask variable.
  11946.  
  11947.  
  11948.  
  11949.  
  11950.  
  11951.  
  11952.                                      Page 186
  11953.  
  11954.                                                            Language Reference
  11955.  
  11956.  
  11957.               source <wordargs>           Read and process statements
  11958.                                           from a file as if they were
  11959.                                           typed into this thread.
  11960.  
  11961.               time <statement>            Execute the statement and
  11962.                                           report how long it took.
  11963.  
  11964.               #                           Comment text up to the end
  11965.                                           of the line.  (To be
  11966.                                           recognized as a valid
  11967.                                           comment, the # must be
  11968.                                           followed by at least one
  11969.                                           space or tab.)
  11970.  
  11971.  
  11972.  
  11973.  
  11974.  
  11975.  
  11976.  
  11977.  
  11978.  
  11979.  
  11980.  
  11981.  
  11982.  
  11983.  
  11984.  
  11985.  
  11986.  
  11987.  
  11988.  
  11989.  
  11990.  
  11991.  
  11992.  
  11993.  
  11994.  
  11995.  
  11996.  
  11997.  
  11998.  
  11999.  
  12000.  
  12001.  
  12002.  
  12003.  
  12004.  
  12005.  
  12006.  
  12007.  
  12008.  
  12009.  
  12010.  
  12011.  
  12012.  
  12013.  
  12014.                                      Page 187
  12015.  
  12016.      Language Reference
  12017.  
  12018.  
  12019.             
  12020.  
  12021.  
  12022.                              Statement Relationships
  12023.  
  12024.  
  12025.             In order of decreasing precedence:
  12026.  
  12027.               Operator                    Meaning                    
  12028.  
  12029.               ( )                         Grouping
  12030.  
  12031.               >     >!     >&     >&!     >>     >>!     >>&     >>&!
  12032.                                           <     <<
  12033.                                           I/O Redirection
  12034.  
  12035.               |     |&                    Piping (stdout only or
  12036.                                           stdout + stderr) between
  12037.                                           concurrent operations
  12038.  
  12039.               ... &                       Background thread or
  12040.                                           process
  12041.  
  12042.               &&     ||                   Conditional execution:
  12043.                                           only if first succeeds or
  12044.                                           only if first fails
  12045.  
  12046.               ;                           Serial execution
  12047.  
  12048.  
  12049.  
  12050.  
  12051.                                  I/O Redirection
  12052.  
  12053.  
  12054.               Operator                    Meaning                    
  12055.  
  12056.               >     >!     >&     >&!     Output to a file (`!'
  12057.                                           allows an existing file to
  12058.                                           be overwritten; `&'
  12059.                                           redirects both stdout and
  12060.                                           stderr.)
  12061.  
  12062.               >>     >>!     >>&     >>&! Append to a file
  12063.  
  12064.               <                           In from a file
  12065.  
  12066.               <<  <string>                Inline data: the text on
  12067.                                           the following lines, up to
  12068.                                           the line containing only
  12069.                                           the specified <string> will
  12070.                                           be fed as stdin to the
  12071.                                           statement.  Unless part of
  12072.                                           <string> is escaped or
  12073.  
  12074.  
  12075.  
  12076.                                      Page 188
  12077.  
  12078.                                                            Language Reference
  12079.  
  12080.  
  12081.                                           single, double or
  12082.                                           backquoted, command and
  12083.                                           variable substitution will
  12084.                                           be done on the inline text.
  12085.  
  12086.  
  12087.                  The grammar  is completely  recursive, so statements
  12088.                  of  arbitrary   complexity  can  be  freely  nested,
  12089.                  conditionally executed, piped or redirected.
  12090.  
  12091.  
  12092.  
  12093.  
  12094.  
  12095.  
  12096.  
  12097.  
  12098.  
  12099.  
  12100.  
  12101.  
  12102.  
  12103.  
  12104.  
  12105.  
  12106.  
  12107.  
  12108.  
  12109.  
  12110.  
  12111.  
  12112.  
  12113.  
  12114.  
  12115.  
  12116.  
  12117.  
  12118.  
  12119.  
  12120.  
  12121.  
  12122.  
  12123.  
  12124.  
  12125.  
  12126.  
  12127.  
  12128.  
  12129.  
  12130.  
  12131.  
  12132.  
  12133.  
  12134.  
  12135.  
  12136.  
  12137.  
  12138.                                      Page 189
  12139.  
  12140.      Language Reference
  12141.  
  12142.  
  12143.             
  12144.  
  12145.  
  12146.                               Expression Operators
  12147.  
  12148.  
  12149.             In order of decreasing precedence:
  12150.  
  12151.               Operator          Meaning                            
  12152.  
  12153.               ( )               Grouping or Procedure call
  12154.                                 arguments
  12155.  
  12156.               { }               Run the enclosed statement list and
  12157.                                 return 1 if it succeeds or 0
  12158.                                 otherwise.
  12159.  
  12160.               [ ]               Array indexing.  (The first element
  12161.                                 is element 0.)
  12162.  
  12163.               -A   -D   -H   -R   -S   -d   -e   -f   -o   -w   -x
  12164.                                 -z
  12165.                                 File system tests
  12166.  
  12167.               ++   --           Prefix and postfix
  12168.                                 increment/decrement
  12169.  
  12170.               ~   -   !   +     Bitwise, arithmetic and logical
  12171.                                 complements and unary plus
  12172.  
  12173.               **                Exponentiation
  12174.  
  12175.               *   /   %   //    Multiplication, Division, Remainder
  12176.                                 and Integer Division
  12177.  
  12178.               +   -             Addition and Subtraction
  12179.  
  12180.               <<   >>           Bit Shifting
  12181.  
  12182.               ==   !=   =~   !~   <   <=   >=   >   Relation-
  12183.                                 testing and pattern-matching
  12184.                                 operators
  12185.  
  12186.               &                 Bit And
  12187.  
  12188.               ^                 Bit Xor
  12189.  
  12190.               |                 Bit Or
  12191.  
  12192.               &&                Logical And
  12193.  
  12194.               ||                Logical Or
  12195.  
  12196.               ?:                Conditional selection
  12197.  
  12198.  
  12199.  
  12200.                                      Page 190
  12201.  
  12202.                                                            Language Reference
  12203.  
  12204.  
  12205.               =   +=   -=   *=   /=   %=   //=   >>=   <<=   &=
  12206.                                 ^=   |=   **=
  12207.                                 Assignment operators
  12208.  
  12209.             Expressions result  in sensible  types, considering  both
  12210.             the types  and the  values of the operands.  For example,
  12211.             10/2 returns  the integer 5 but 5/2 produces the floating
  12212.             point value 2.5.  Also, the integer 1, the floating point
  12213.             value 1.0 and the string ``1'' all compare equal.
  12214.  
  12215.  
  12216.  
  12217.  
  12218.  
  12219.  
  12220.  
  12221.  
  12222.  
  12223.  
  12224.  
  12225.  
  12226.  
  12227.  
  12228.  
  12229.  
  12230.  
  12231.  
  12232.  
  12233.  
  12234.  
  12235.  
  12236.  
  12237.  
  12238.  
  12239.  
  12240.  
  12241.  
  12242.  
  12243.  
  12244.  
  12245.  
  12246.  
  12247.  
  12248.  
  12249.  
  12250.  
  12251.  
  12252.  
  12253.  
  12254.  
  12255.  
  12256.  
  12257.  
  12258.  
  12259.  
  12260.  
  12261.  
  12262.                                      Page 191
  12263.  
  12264.      Language Reference
  12265.  
  12266.  
  12267.             
  12268.  
  12269.  
  12270.                                 File System Tests
  12271.  
  12272.  
  12273.             The operand  of a  file system  test is  interpreted as a
  12274.             word, not an expression, and may involve wildcarding.  If
  12275.             wildcarding produces  more than  one match,  the test  is
  12276.             done on the first one.
  12277.  
  12278.               Prefix Operator   True if                            
  12279.  
  12280.               -A                Archive Bit Set
  12281.  
  12282.               -D     -d         Directory
  12283.  
  12284.               -H                Hidden File or Directory
  12285.  
  12286.               -R                Read-only File or Directory
  12287.  
  12288.               -S                System File or Directory
  12289.  
  12290.               -e                File or Directory Exists
  12291.  
  12292.               -f                Ordinary File
  12293.  
  12294.               -o                Ownership (Same as Existence on an
  12295.                                 OS/2 or NT FAT file system)
  12296.  
  12297.               -r                Readable (Same as ordinary file on
  12298.                                 an OS/2 or NT FAT file system)
  12299.  
  12300.               -w                Writable (Not Read-only and not a
  12301.                                 directory)
  12302.  
  12303.               -x                Executable (Has a .csh, .exe, .com
  12304.                                 or .cmd extension and, if it's an
  12305.                                 .exe or a .com file, appears to be
  12306.                                 a valid OS/2 or NT binary
  12307.                                 executable.)
  12308.  
  12309.               -z                Zero-length File
  12310.  
  12311.  
  12312.                  Example:     if (-d $a) then
  12313.                                 echo $a is a directory
  12314.                               end
  12315.  
  12316.  
  12317.  
  12318.  
  12319.  
  12320.  
  12321.  
  12322.  
  12323.  
  12324.                                      Page 192
  12325.  
  12326.                                                            Language Reference
  12327.  
  12328.  
  12329.             
  12330.  
  12331.  
  12332.                                  Special Devices
  12333.  
  12334.  
  12335.               Name              Use                                
  12336.  
  12337.               aux+              The auxiliary port.
  12338.  
  12339.               clock$+           The OS/2 system clock.
  12340.  
  12341.               con               The OS/2 console.  This is the text
  12342.                                 window the shell is running in.
  12343.                                 Reading from it reads the keyboard;
  12344.                                 writing to it writes to the screen.
  12345.  
  12346.               conin$            The NT console keyboard.  A read-
  12347.                                 only device.
  12348.  
  12349.               conout$           The NT console display.  A write-
  12350.                                 only device.
  12351.  
  12352.               com1 .. com7      The various async communication
  12353.                                 ports you may have.  They can be
  12354.                                 read or written.
  12355.  
  12356.               kbd$              The OS/2 keyboard.  A read-only
  12357.                                 device.
  12358.  
  12359.               lpt1 .. lpt4+     The line printer ports.
  12360.  
  12361.               nul               The null device.  Reads return end-
  12362.                                 of-file; writes are discarded.
  12363.  
  12364.               prn               The print spooler queue.
  12365.  
  12366.               pointer$+         The OS/2 mouse and on-screen
  12367.                                 pointer combination.  Reads from
  12368.                                 the mouse; writes to the screen.
  12369.  
  12370.               screen$           The OS/2 text window. A write-only
  12371.                                 device.
  12372.  
  12373.  
  12374.                  Hamilton C  shell recognizes the OS/2 and NT special
  12375.                  device names regardless of whether they are typed in
  12376.                  upper or  lower case and regardless of whether there
  12377.                  is a trailing colon.  For example, COM1: is the same
  12378.                  as COM1  is the same as com1.  Remember to quote the
  12379.                  device name if it has a dollar sign at the end so it
  12380.                  won't be  misinterpreted as  the start of a variable
  12381.                  reference.
  12382.  
  12383.  
  12384.  
  12385.  
  12386.                                      Page 193
  12387.  
  12388.      Language Reference
  12389.  
  12390.  
  12391.                  Not all  devices will be installed on any particular
  12392.                  machine.  Also, the exact behavior of any device may
  12393.                  depend which  manufacturer  supplied  it.    Devices
  12394.                  marked with  + should  only be  accessed  with  some
  12395.                  caution.
  12396.  
  12397.  
  12398.  
  12399.  
  12400.  
  12401.  
  12402.  
  12403.  
  12404.  
  12405.  
  12406.  
  12407.  
  12408.  
  12409.  
  12410.  
  12411.  
  12412.  
  12413.  
  12414.  
  12415.  
  12416.  
  12417.  
  12418.  
  12419.  
  12420.  
  12421.  
  12422.  
  12423.  
  12424.  
  12425.  
  12426.  
  12427.  
  12428.  
  12429.  
  12430.  
  12431.  
  12432.  
  12433.  
  12434.  
  12435.  
  12436.  
  12437.  
  12438.  
  12439.  
  12440.  
  12441.  
  12442.  
  12443.  
  12444.  
  12445.  
  12446.  
  12447.  
  12448.                                      Page 194
  12449.  
  12450.                                                            Language Reference
  12451.  
  12452.  
  12453.             
  12454.  
  12455.  
  12456.                         Wildcarding and Pattern Matching
  12457.  
  12458.  
  12459.               Characters        Meaning                            
  12460.  
  12461.               ?                 Match any single character,
  12462.                                 including `.' but not `\' or '/'.
  12463.  
  12464.               *                 Match any number of characters,
  12465.                                 including `.' but not '\' or '/'.
  12466.  
  12467.               [a-z]             An example range:  match any
  12468.                                 character a through z.
  12469.  
  12470.               [^a-z]            An example exclusion range: match
  12471.                                 any character not in the set a
  12472.                                 through z.
  12473.  
  12474.               {a,b}c            Alternation:  generate both ac and
  12475.                                 bc.
  12476.  
  12477.               ...               Indefinite Directory:  match any
  12478.                                 number of directory levels -- zero
  12479.                                 or more -- whatever it takes to
  12480.                                 make the rest of the pattern match.
  12481.  
  12482.  
  12483.                  Patterns are  used  both  for  traditional  filename
  12484.                  wildcarding in  word mode  and for examining strings
  12485.                  in  expression   mode.     Patterns   are   nestable
  12486.                  arbitrarily and  a recursive comparison algorithm is
  12487.                  used to  guarantee a  sensible result  no matter how
  12488.                  complex the  pattern.   For example:   *r*  or  even
  12489.                  *\[a-c]*.[ch] operate sensibly.
  12490.  
  12491.                  Filename wildcards  can be  used wherever  a word is
  12492.                  expected and  will match  any filename  except ``.''
  12493.                  and ``..'' unless it's marked ``hidden.''  (To allow
  12494.                  wildcarding to  match hidden files, set nonohidden =
  12495.                  1.)   Quoting the  word prevents wildcarding.  Since
  12496.                  filenames  are   not  case   sensitive,     filename
  12497.                  wildcarding isn't either.
  12498.  
  12499.                  A pattern can also be used  to examine a string in a
  12500.                  switch  statement   or  with   the  ``=~''  (pattern
  12501.                  matches)  and   ``!~''  (pattern  fails)  expression
  12502.                  operators.   In this  context, the  pattern must  be
  12503.                  inside quotes, since otherwise it would be parsed as
  12504.                  an  expression,  with  ``*''  being  viewed  as  the
  12505.                  multiply operator,  etc.   When examining  a  string
  12506.                  with a  pattern that  uses alternation,  the pattern
  12507.  
  12508.  
  12509.  
  12510.                                      Page 195
  12511.  
  12512.      Language Reference
  12513.  
  12514.  
  12515.                  ``matches'' if  any  of  the  alternatives  matches.
  12516.                  When matching strings, case does matter.
  12517.  
  12518.                  When using a pattern to examine a string with ``=~''
  12519.                  or ``!~''  or with a switch, the string being tested
  12520.                  is the left operand and the pattern is on the right.
  12521.  
  12522.  
  12523.  
  12524.  
  12525.  
  12526.  
  12527.  
  12528.  
  12529.  
  12530.  
  12531.  
  12532.  
  12533.  
  12534.  
  12535.  
  12536.  
  12537.  
  12538.  
  12539.  
  12540.  
  12541.  
  12542.  
  12543.  
  12544.  
  12545.  
  12546.  
  12547.  
  12548.  
  12549.  
  12550.  
  12551.  
  12552.  
  12553.  
  12554.  
  12555.  
  12556.  
  12557.  
  12558.  
  12559.  
  12560.  
  12561.  
  12562.  
  12563.  
  12564.  
  12565.  
  12566.  
  12567.  
  12568.  
  12569.  
  12570.  
  12571.  
  12572.                                      Page 196
  12573.  
  12574.                                                            Language Reference
  12575.  
  12576.  
  12577.  
  12578.                                Filename Completion
  12579.  
  12580.  
  12581.  
  12582.  
  12583.             Filename completion  lets you type just the first part of
  12584.             a filename  and have  the shell  fill in  the rest.   The
  12585.             variations are:   using  the F  key  for  basic  filename
  12586.             completion, the  D key  if you  want all  the  duplicates
  12587.             listed or  Tab or  Shift-Tab (BackTab) to move forward or
  12588.             backward through the list one-by-one.
  12589.  
  12590.  
  12591.               Key               Meaning                              
  12592.  
  12593.               Alt-F or Ctrl-F   Filename completion.  Appending the
  12594.                                 ``*'' wildcard character onto the
  12595.                                 end, use the previous word as a
  12596.                                 wildcard pattern.  If it matches a
  12597.                                 single file, substitute it in with a
  12598.                                 space following.  (If you don't want
  12599.                                 a space following, use the -N option
  12600.                                 when you start the C shell.)
  12601.  
  12602.                                 If there were multiple matches, but
  12603.                                 they all had some common front-part
  12604.                                 that fully ``used up'' the pattern,
  12605.                                 substitute in just that common front-
  12606.                                 part and show it in the color
  12607.                                 specified by the DUPLICATES variable
  12608.                                 (default is green).
  12609.  
  12610.                                 If substitution wasn't possible,
  12611.                                 highlight the pattern in the color
  12612.                                 specified by the MATCHFAIL variable
  12613.                                 (default is bright red).  (Any
  12614.                                 highlighting color is turned off when
  12615.                                 you press the next keystroke.)
  12616.  
  12617.               Alt-D or Ctrl-D   Duplicate completions.  Same
  12618.                                 wildcarding, but if there are
  12619.                                 multiple matches, show them all with
  12620.                                 a space following.  (Here again, if
  12621.                                 you don't want a space following, use
  12622.                                 the -N option when you start the C
  12623.                                 shell.)  If there were no matches,
  12624.                                 highlight the pattern in the color
  12625.                                 specified by the MATCHFAIL variable
  12626.                                 (default is bright red).
  12627.  
  12628.               <Tab>             Next filename.  Move one-by-one
  12629.                                 through the list of matching
  12630.                                 filenames.  After the last, paste the
  12631.  
  12632.  
  12633.  
  12634.                                      Page 197
  12635.  
  12636.      Language Reference
  12637.  
  12638.  
  12639.                                 original back in place, highlighting
  12640.                                 with the MATCHFAIL color, then
  12641.                                 continue, with the next Tab, cycling
  12642.                                 through the list again.  (To type an
  12643.                                 ordinary tab character, use Ctrl-
  12644.                                 <Tab>.  Alternately, if the C shell
  12645.                                 is started with the -T option, the
  12646.                                 Tab key generates a plain tab
  12647.                                 character and Ctrl-<Tab> is the
  12648.                                 filename completion key.)
  12649.  
  12650.               Shift-<Tab>       Previous filename.  Same as Tab, but
  12651.                                 cycling in reverse through the list.
  12652.  
  12653.  
  12654.  
  12655.  
  12656.  
  12657.  
  12658.  
  12659.  
  12660.  
  12661.  
  12662.  
  12663.  
  12664.  
  12665.  
  12666.  
  12667.  
  12668.  
  12669.  
  12670.  
  12671.  
  12672.  
  12673.  
  12674.  
  12675.  
  12676.  
  12677.  
  12678.  
  12679.  
  12680.  
  12681.  
  12682.  
  12683.  
  12684.  
  12685.  
  12686.  
  12687.  
  12688.  
  12689.  
  12690.  
  12691.  
  12692.  
  12693.  
  12694.  
  12695.  
  12696.                                      Page 198
  12697.  
  12698.                                                            Language Reference
  12699.  
  12700.  
  12701.                               Command Line Editing
  12702.  
  12703.  
  12704.               Key          Meaning                                   
  12705.  
  12706.  
  12707.  
  12708.  
  12709.  
  12710.  
  12711.  
  12712.  
  12713.  
  12714.  
  12715.  
  12716.  
  12717.  
  12718.  
  12719.  
  12720.  
  12721.  
  12722.  
  12723.  
  12724.  
  12725.  
  12726.  
  12727.  
  12728.  
  12729.  
  12730.  
  12731.  
  12732.  
  12733.  
  12734.  
  12735.  
  12736.  
  12737.  
  12738.  
  12739.  
  12740.  
  12741.  
  12742.  
  12743.  
  12744.  
  12745.  
  12746.  
  12747.  
  12748.  
  12749.  
  12750.  
  12751.  
  12752.  
  12753.  
  12754.  
  12755.  
  12756.  
  12757.  
  12758.                                      Page 199
  12759.  
  12760.      Language Reference
  12761.  
  12762.  
  12763.               <Enter>      Accept the command as typed.  Move to the
  12764.                            end (if not there already) and carriage
  12765.                            return to a new line.
  12766.               <Home>       Beginning of command line.
  12767.               <End>        End of command line.
  12768.               <Up>         Up one command in the history list.  Each
  12769.                            time it's pressed, it displays the
  12770.                            preceding entry in the history list.  Any
  12771.                            ``!...'' or ``%...'' history references in
  12772.                            the original text will have been fixed up
  12773.                            unless it was the immediately preceding
  12774.                            command and it had one these references
  12775.                            that failed.  If already at the first
  12776.                            entry, the command line is highlighted in
  12777.                            bright red.
  12778.               <Down>       Down one command line in the history list.
  12779.                            If already at the latest entry, the
  12780.                            command line is highlighted in bright red.
  12781.               <Left>       One character left.
  12782.               <Right>      One character right.
  12783.               Ctrl-<Home>  Move to the upper-leftmost character in
  12784.                            the current screenful if the command is
  12785.                            long enough that it actually wraps across
  12786.                            several screens.
  12787.               Ctrl-<End>   Move to the lower-rightmost character in
  12788.                            the current screenful.
  12789.               Ctrl-<Up>    Up one row on the screen if the command is
  12790.                            long enough that it runs over a row.
  12791.               Ctrl-<Down>  Down one row on the screen.
  12792.               Ctrl-<Left>  Backup word.
  12793.               Ctrl-<Right> Forward word.
  12794.               Alt-<Home>   Delete all preceding characters on the
  12795.                            command line.
  12796.               Alt-<End>    Delete all following characters.
  12797.               Alt-<Up>     Delete up one row on the screen if the
  12798.                            command runs over a row.
  12799.               Alt-<Down>   Delete down one row.
  12800.               Alt-<Left>   Delete preceding word.
  12801.               Ctrl-<Backspace>
  12802.               Alt-<Right>  Delete following word.
  12803.               <Insert>     Toggle insert/overstrike mode.  When
  12804.                            inserting, the cursor is slightly thicker.
  12805.               Ctrl-<Insert>     Insert the next word from the last
  12806.                            section of deleted text.  When it reaches
  12807.                            the end of the deleted text, it starts
  12808.                            over.
  12809.               Alt-<Insert> Insert all the rest of the previously
  12810.                            deleted text.
  12811.               <PageUp>     Backup to one past the last history
  12812.                            reference.  (Repeatedly typing <PageUp>
  12813.                            <Enter> is a convenient way of picking up
  12814.                            a whole series of commands from history.)
  12815.               <PageDown>   Forward to the newest entry in the history
  12816.                            list.
  12817.  
  12818.  
  12819.  
  12820.                                      Page 200
  12821.  
  12822.                                                            Language Reference
  12823.  
  12824.  
  12825.               <Esc>        Clear the command line.
  12826.  
  12827.               Note:  Users lacking separate arrow keys must press
  12828.               Ctrl-Shift instead of Alt.
  12829.  
  12830.             
  12831.  
  12832.  
  12833.  
  12834.  
  12835.  
  12836.  
  12837.  
  12838.  
  12839.  
  12840.  
  12841.  
  12842.  
  12843.  
  12844.  
  12845.  
  12846.  
  12847.  
  12848.  
  12849.  
  12850.  
  12851.  
  12852.  
  12853.  
  12854.  
  12855.  
  12856.  
  12857.  
  12858.  
  12859.  
  12860.  
  12861.  
  12862.  
  12863.  
  12864.  
  12865.  
  12866.  
  12867.  
  12868.  
  12869.  
  12870.  
  12871.  
  12872.  
  12873.  
  12874.  
  12875.  
  12876.  
  12877.  
  12878.  
  12879.  
  12880.  
  12881.  
  12882.                                      Page 201
  12883.  
  12884.      Language Reference
  12885.  
  12886.  
  12887.  
  12888.                                  History Recall
  12889.  
  12890.  
  12891.               Command           Meaning                            
  12892.  
  12893.               !!                Last command
  12894.  
  12895.               !^                First argument word of last command
  12896.  
  12897.               !$                Last word of last command
  12898.  
  12899.               !*                All arguments of last command
  12900.  
  12901.               !n                Command n
  12902.  
  12903.               !-n               nth command from the last
  12904.  
  12905.               !str              Last command starting with str
  12906.  
  12907.               !?str?            Last command containing str
  12908.  
  12909.               %str1%str2%       Substitute str2 for str1 in last
  12910.                                 command. (Used only at the
  12911.                                 beginning of a line.)
  12912.  
  12913.  
  12914.                  History recall  allows a  previous statement  to  be
  12915.                  quickly recalled  and re-executed.  It's a very fast
  12916.                  shorthand, especially in the edit/compile/debug loop
  12917.                  or to  fix a  typo.  For convenience, ``!'' is taken
  12918.                  as an ordinary character if followed by white space,
  12919.                  ``='', ``~'' or ``(''.
  12920.  
  12921.                  If you  want, you can choose different characters to
  12922.                  introduce  history   references  by   changing   the
  12923.                  histchars variable.
  12924.  
  12925.  
  12926.  
  12927.                                Command Completion
  12928.  
  12929.  
  12930.             Command completion  lets you type just part of a previous
  12931.             command and  have the  shell fill  in the  rest.  As with
  12932.             filename  completion,   if  no   match  is  found,  color
  12933.             highlighting  as   defined  by   the  MATCHFAIL  variable
  12934.             (default is  bright  red)  will  be  used.    Consecutive
  12935.             depressions cause  the search to continue on back through
  12936.             the history list.
  12937.  
  12938.               Key               Meaning                            
  12939.  
  12940.  
  12941.  
  12942.  
  12943.  
  12944.                                      Page 202
  12945.  
  12946.                                                            Language Reference
  12947.  
  12948.  
  12949.               Ctrl-<Enter>      Search for the last command that
  12950.                                 starts with the characters in the
  12951.                                 previous word.
  12952.  
  12953.               Alt-<Enter>       Search for the last command that
  12954.                                 contains the characters in the
  12955.                                 previous word anywhere on the
  12956.                                 command line.
  12957.  
  12958.  
  12959.  
  12960.  
  12961.  
  12962.  
  12963.  
  12964.  
  12965.  
  12966.  
  12967.  
  12968.  
  12969.  
  12970.  
  12971.  
  12972.  
  12973.  
  12974.  
  12975.  
  12976.  
  12977.  
  12978.  
  12979.  
  12980.  
  12981.  
  12982.  
  12983.  
  12984.  
  12985.  
  12986.  
  12987.  
  12988.  
  12989.  
  12990.  
  12991.  
  12992.  
  12993.  
  12994.  
  12995.  
  12996.  
  12997.  
  12998.  
  12999.  
  13000.  
  13001.  
  13002.  
  13003.  
  13004.  
  13005.  
  13006.                                      Page 203
  13007.  
  13008.      Language Reference
  13009.  
  13010.  
  13011.             
  13012.  
  13013.  
  13014.                                      Quoting
  13015.  
  13016.  
  13017.               String            Meaning                            
  13018.  
  13019.               '...'             Literal character string.  Only do
  13020.                                 history substitutions.
  13021.  
  13022.               "..."             Single word.  Typically used if
  13023.                                 there are embedded blanks or
  13024.                                 wildcard characters you want
  13025.                                 treated as ordinary.  Has no effect
  13026.                                 on command or variable
  13027.                                 substitutions:  they're still done.
  13028.  
  13029.               `...`             Command substitution.  Evaluate the
  13030.                                 string as a separate command and
  13031.                                 substitute its output back onto the
  13032.                                 command line.  Newlines are turned
  13033.                                 into spaces and Ansi escape
  13034.                                 sequences (for highlighting, etc.)
  13035.                                 are filtered out.
  13036.  
  13037.               ^                 Quote just the next character.  Use
  13038.                                 to remove any special meaning from
  13039.                                 the next character, to specify a
  13040.                                 character by its binary value or to
  13041.                                 specify one following non-printable
  13042.                                 characters.  If the NewLine
  13043.                                 character at the end of a line is
  13044.                                 quoted this way, it's treated as
  13045.                                 ordinary white space.  (You can
  13046.                                 choose a different escape character
  13047.                                 by changing the escapesym
  13048.                                 variable.)
  13049.  
  13050.  
  13051.  
  13052.  
  13053.                                 Escape Sequences
  13054.  
  13055.  
  13056.               String            Meaning                            
  13057.  
  13058.               ^a                Audible alert (bell)
  13059.               ^b                Backspace
  13060.               ^f                Form Feed
  13061.               ^n                New Line
  13062.               ^r                Carriage Return
  13063.               ^t                Tab
  13064.               ^v                Vertical Tab
  13065.  
  13066.  
  13067.  
  13068.                                      Page 204
  13069.  
  13070.                                                            Language Reference
  13071.  
  13072.  
  13073.               ^^                Single escapesym character
  13074.  
  13075.  
  13076.  
  13077.  
  13078.  
  13079.  
  13080.  
  13081.  
  13082.  
  13083.  
  13084.  
  13085.  
  13086.  
  13087.  
  13088.  
  13089.  
  13090.  
  13091.  
  13092.  
  13093.  
  13094.  
  13095.  
  13096.  
  13097.  
  13098.  
  13099.  
  13100.  
  13101.  
  13102.  
  13103.  
  13104.  
  13105.  
  13106.  
  13107.  
  13108.  
  13109.  
  13110.  
  13111.  
  13112.  
  13113.  
  13114.  
  13115.  
  13116.  
  13117.  
  13118.  
  13119.  
  13120.  
  13121.  
  13122.  
  13123.  
  13124.  
  13125.  
  13126.  
  13127.  
  13128.  
  13129.  
  13130.                                      Page 205
  13131.  
  13132.      Language Reference
  13133.  
  13134.  
  13135.             
  13136.             
  13137.             
  13138.             
  13139.  
  13140.  
  13141.                               Variable Substitution
  13142.  
  13143.  
  13144.               Reference                   Meaning                    
  13145.  
  13146.               $var     ${var}             value of variable var
  13147.  
  13148.               $var[<expr>]     ${var[<expr>]}  value of var, indexed
  13149.                                           by an arbitrarily complex
  13150.                                           expression
  13151.  
  13152.               $#var     ${#var}           Number of words in var
  13153.  
  13154.               $?var     ${?var}           1 if var exists; 0
  13155.                                           otherwise
  13156.  
  13157.               $procname( <argument list> )     Procedure reference,
  13158.                                           used as a variable
  13159.                                           substitution.  The
  13160.                                           arguments are expressions,
  13161.                                           separated by commas.  Any
  13162.                                           value returned by the
  13163.                                           procedure will be
  13164.                                           substituted in place.
  13165.  
  13166.               $<                          Pseudo-variable result of
  13167.                                           reading one line from stdin
  13168.                                           each time it's evaluated
  13169.  
  13170.               $*                          Same as $argv
  13171.  
  13172.               $0 .. $9                    Same as $argv[0] ..
  13173.                                           $argv[9]
  13174.  
  13175.  
  13176.                  Variable substitution  is typically used to pass the
  13177.                  value of  a variable  as an  argument to  a command.
  13178.                  For example:  cl -AS -G2 -Zi $a.c
  13179.  
  13180.  
  13181.  
  13182.  
  13183.  
  13184.  
  13185.  
  13186.  
  13187.  
  13188.  
  13189.  
  13190.  
  13191.  
  13192.                                      Page 206
  13193.  
  13194.                                                            Language Reference
  13195.  
  13196.  
  13197.             
  13198.  
  13199.  
  13200.                              Substitution Modifiers
  13201.  
  13202.  
  13203.               Operator                    Meaning                    
  13204.  
  13205.               :n                          nth word
  13206.  
  13207.               :#                          Count the number of words
  13208.  
  13209.               :^                          Word number 1, counting
  13210.                                           from 0
  13211.  
  13212.               :$                          Last word
  13213.  
  13214.               :%                          Word matched by a !?str?
  13215.                                           history search
  13216.  
  13217.               :n-m                        nth through mth words
  13218.  
  13219.               :-n                         0 through nth words
  13220.  
  13221.               :n-                         n through next-to-last
  13222.                                           words
  13223.  
  13224.               :n*                         n through last word
  13225.  
  13226.               :*                          1 through last word
  13227.  
  13228.               :q                          Single quote each word
  13229.  
  13230.               :s/str1/str2/               Substitute str2 for str1
  13231.                                           and then reparse into
  13232.                                           words.  Match failures are
  13233.                                           considered to be errors
  13234.                                           unless ignoreerrors == 2.
  13235.  
  13236.               :S/str1/str2/               Substitute str2 for str1
  13237.                                           but leave it as a single
  13238.                                           string.  Also, failure to
  13239.                                           match is not considered an
  13240.                                           error.
  13241.  
  13242.               :&                          Repeat last substitution
  13243.  
  13244.               :g...                       Global editing:  apply the
  13245.                                           edit operation everywhere
  13246.                                           it matches, not just the
  13247.                                           first occurrence.
  13248.  
  13249.               :x                          Treat each word as a string
  13250.                                           and break it up into words
  13251.  
  13252.  
  13253.  
  13254.                                      Page 207
  13255.  
  13256.      Language Reference
  13257.  
  13258.  
  13259.               :p                          Print the substitution but
  13260.                                           don't execute the
  13261.                                           statement.  (Ignored except
  13262.                                           in history substitutions.)
  13263.  
  13264.  
  13265.                  Substitution  modifiers   can  be   applied  to  any
  13266.                  command, variable  or history  substitution.   Also,
  13267.                  any number in a row can be applied, as desired.
  13268.  
  13269.  
  13270.  
  13271.  
  13272.  
  13273.  
  13274.  
  13275.  
  13276.  
  13277.  
  13278.  
  13279.  
  13280.  
  13281.  
  13282.  
  13283.  
  13284.  
  13285.  
  13286.  
  13287.  
  13288.  
  13289.  
  13290.  
  13291.  
  13292.  
  13293.  
  13294.  
  13295.  
  13296.  
  13297.  
  13298.  
  13299.  
  13300.  
  13301.  
  13302.  
  13303.  
  13304.  
  13305.  
  13306.  
  13307.  
  13308.  
  13309.  
  13310.  
  13311.  
  13312.  
  13313.  
  13314.  
  13315.  
  13316.                                      Page 208
  13317.  
  13318.                                                            Language Reference
  13319.  
  13320.  
  13321.             
  13322.             
  13323.             
  13324.             
  13325.  
  13326.  
  13327.                            Pathname Editing on x\y\z.c
  13328.  
  13329.  
  13330.               Operator  Name      Description            Result    
  13331.  
  13332.               :h        head      Directory containing   x\y
  13333.  
  13334.               :r        root      Path w/o .ext          x\y\z
  13335.  
  13336.               :t        tail      Simple filename        z.c
  13337.  
  13338.               :b        base      Filename w/o .ext      z
  13339.  
  13340.               :e        ext       .ext w/o the ``.''     c
  13341.  
  13342.               :f        fullpath  Fully-qualified name   d:\bob\x\y\z
  13343.               .c
  13344.  
  13345.  
  13346.                  Pathname editing  can be  applied  to  any  command,
  13347.                  variable or  history substitution.  Also, any number
  13348.                  of pathname  editing operations  can be applied, one
  13349.                  after the other, to a given substitution.
  13350.  
  13351.                  Example:  echo $path:gt
  13352.  
  13353.  
  13354.  
  13355.  
  13356.  
  13357.  
  13358.  
  13359.  
  13360.  
  13361.  
  13362.  
  13363.  
  13364.  
  13365.  
  13366.  
  13367.  
  13368.  
  13369.  
  13370.  
  13371.  
  13372.  
  13373.  
  13374.  
  13375.  
  13376.  
  13377.  
  13378.                                      Page 209
  13379.  
  13380.      Language Reference
  13381.  
  13382.  
  13383.             
  13384.  
  13385.  
  13386.  
  13387.  
  13388.  
  13389.  
  13390.  
  13391.  
  13392.  
  13393.  
  13394.  
  13395.  
  13396.  
  13397.  
  13398.  
  13399.  
  13400.  
  13401.  
  13402.  
  13403.  
  13404.  
  13405.  
  13406.  
  13407.  
  13408.  
  13409.  
  13410.  
  13411.  
  13412.  
  13413.  
  13414.  
  13415.  
  13416.  
  13417.  
  13418.  
  13419.  
  13420.  
  13421.  
  13422.  
  13423.  
  13424.  
  13425.  
  13426.  
  13427.  
  13428.  
  13429.  
  13430.  
  13431.  
  13432.  
  13433.  
  13434.  
  13435.  
  13436.  
  13437.  
  13438.  
  13439.  
  13440.                                      Page 210
  13441.  
  13442.                                                          Predefined Variables
  13443.  
  13444.  
  13445.  
  13446.                        Environmental Variables Recognized
  13447.  
  13448.  
  13449.             Name          Default  Use                                  
  13450.  
  13451.             ADDITIONSBright Green  Lines added found by diff.
  13452.  
  13453.             CDPATH                 List of directories to search for
  13454.                                    the subdirectory specified as the
  13455.                                    new current directory.
  13456.  
  13457.             COLORS White on Black  Normal screen colors.
  13458.  
  13459.             COMSPEC                Usually, this is the pathname of
  13460.                                    cmd.exe.  If you set it to point
  13461.                                    to the C shell, e.g., so other
  13462.                                    programs will invoke the C shell
  13463.                                    rather than cmd.exe, the C shell
  13464.                                    will try to look through the
  13465.                                    search path for cmd.exe if it
  13466.                                    needs to run a .cmd file.
  13467.  
  13468.             CSHOPTIONS             Default set of command line
  13469.                                    options to be pasted ahead of any
  13470.                                    other command line options passed
  13471.                                    to csh.exe.
  13472.  
  13473.             DELETIONS  Bright Red  Lines deleted found by diff.
  13474.  
  13475.             DIRECTORIES    Bright  Directories listed by ls.
  13476.  
  13477.             DRIVEMASK              Used by du.exe, pwd.exe and vl.exe
  13478.                                    to limit the default list of
  13479.                                    drives it will report on.  Written
  13480.                                    as a list of alphabetic characters
  13481.                                    representing the drives you want
  13482.                                    listed; ranges are allowed.  If
  13483.                                    you don't define this variable,
  13484.                                    all drives beginning with C: are
  13485.                                    normally reported.
  13486.  
  13487.             DUPLICATES      Green  When filename completion matches
  13488.                                    matches more than one name.
  13489.  
  13490.             ESCAPESYM           ^  Character to be interpreted as a
  13491.                                    literal escape character.  Placed
  13492.                                    in the environment only if it is
  13493.                                    not the default circumflex.
  13494.  
  13495.             FOREIGNFILESBright Red Filetypes in a tar file that have
  13496.                                    no counterpart on OS/2.
  13497.  
  13498.             HIGHLIGHT      Bright  Current disk or directory.
  13499.  
  13500.  
  13501.  
  13502.                                      Page 211
  13503.  
  13504.      Predefined Variables
  13505.  
  13506.  
  13507.             HOME                   Home directory (default is the
  13508.                                    initial current directory.)
  13509.  
  13510.             LSOPTIONS              Default set of command line
  13511.                                    options to be pasted ahead of any
  13512.                                    other command line options passed
  13513.                                    to ls.exe.
  13514.  
  13515.             MATCHFAIL  Bright Red  When filename or command
  13516.                                    completion doesn't match anything.
  13517.  
  13518.  
  13519.  
  13520.  
  13521.  
  13522.  
  13523.  
  13524.  
  13525.  
  13526.  
  13527.  
  13528.  
  13529.  
  13530.  
  13531.  
  13532.  
  13533.  
  13534.  
  13535.  
  13536.  
  13537.  
  13538.  
  13539.  
  13540.  
  13541.  
  13542.  
  13543.  
  13544.  
  13545.  
  13546.  
  13547.  
  13548.  
  13549.  
  13550.  
  13551.  
  13552.  
  13553.  
  13554.  
  13555.  
  13556.  
  13557.  
  13558.  
  13559.  
  13560.  
  13561.  
  13562.  
  13563.  
  13564.                                      Page 212
  13565.  
  13566.                                                          Predefined Variables
  13567.  
  13568.  
  13569.  
  13570.                        Environmental Variables Recognized
  13571.  
  13572.  
  13573.             Name          Default  Use                                  
  13574.  
  13575.             MIXEDCASEDRIVES        List of drives and UNC names for
  13576.                                    which ls.exe,  pwd.exe,
  13577.                                    wildcarding and the fullname and
  13578.                                    current directory functions should
  13579.                                    report filenames in mixed case
  13580.                                    rather than all lower case.
  13581.  
  13582.             MOREEOF         Green  End or Top of File in more.
  13583.  
  13584.             MOREERRORBright Yellow Unrecognizable command to more.
  13585.  
  13586.             MOREFILLIN      White  User response to more prompt.
  13587.  
  13588.             MOREPROMPT      Green  Prompt line in more.
  13589.  
  13590.             MORETOPMEMBright Yellow                                     
  13591.                                    Top of Memory message from more.
  13592.  
  13593.             NETWORKBUG             If NETWORKBUG = 1, the shell and
  13594.                                    all the utilities will read
  13595.                                    directory entries only one-at-a-
  13596.                                    time as a workaround for a
  13597.                                    networking bug.  (Not used on NT.)
  13598.  
  13599.             PATH                   Search path for executable files.
  13600.  
  13601.             PROMPT1    $@ $CDISK%  Primary command prompt template.
  13602.  
  13603.             PROMPT2    $@ $CDISK?  Continuation line prompt template.
  13604.  
  13605.             RADIX              16  Default radix used by more.exe and
  13606.                                    other utilities when displaying
  13607.                                    binary data.
  13608.  
  13609.             SHELL                  Always set to the pathname of the
  13610.                                    Hamilton C shell csh.exe file.
  13611.  
  13612.             SWITCHCHARS        -/  Characters that can be used as
  13613.                                    option introducers for the shell
  13614.                                    and utilities.
  13615.  
  13616.             SYSTEMDIRSBright Green Used by ls.exe for directories
  13617.                                    with the System bit on.
  13618.  
  13619.             SYSTEMFILES     Green  Used by ls.exe for files with the
  13620.                                    System bit on.
  13621.  
  13622.  
  13623.  
  13624.  
  13625.  
  13626.                                      Page 213
  13627.  
  13628.      Predefined Variables
  13629.  
  13630.  
  13631.             TABS                8  Used by more.exe, head.exe,
  13632.                                    tail.exe and tabs.exe to tell them
  13633.                                    how many character positions there
  13634.                                    are between tab stops.
  13635.  
  13636.             TAPE        \\.\tape0  Used by mt.exe under Windows NT to
  13637.                                    specify the pathname of the
  13638.                                    default tape drive.
  13639.  
  13640.  
  13641.  
  13642.  
  13643.  
  13644.  
  13645.  
  13646.  
  13647.  
  13648.  
  13649.  
  13650.  
  13651.  
  13652.  
  13653.  
  13654.  
  13655.  
  13656.  
  13657.  
  13658.  
  13659.  
  13660.  
  13661.  
  13662.  
  13663.  
  13664.  
  13665.  
  13666.  
  13667.  
  13668.  
  13669.  
  13670.  
  13671.  
  13672.  
  13673.  
  13674.  
  13675.  
  13676.  
  13677.  
  13678.  
  13679.  
  13680.  
  13681.  
  13682.  
  13683.  
  13684.  
  13685.  
  13686.  
  13687.  
  13688.                                      Page 214
  13689.  
  13690.                                                          Predefined Variables
  13691.  
  13692.  
  13693.  
  13694.                        Environmental Variables Recognized
  13695.  
  13696.  
  13697.             Name          Default  Use                                  
  13698.  
  13699.             TZ                     Used by tar.exe under OS/2 to tell
  13700.                                    it how to convert between local
  13701.                                    time and GMT.  (Under Windows NT,
  13702.                                    the system keeps track of the
  13703.                                    difference between local time and
  13704.                                    GMT, so the TZ variable is not
  13705.                                    needed.)  The TZ variable should
  13706.                                    be of the form of a three-letter
  13707.                                    timezone, e.g., EST, followed by a
  13708.                                    signed number giving the
  13709.                                    difference in hours between GMT
  13710.                                    and local time, followed by an
  13711.                                    optional daylight savings
  13712.                                    timezone.  Examples are EST5EDT in
  13713.                                    New York or PST8PDT in California.
  13714.  
  13715.  
  13716.                  Environmental variables  are  passed  to  any  child
  13717.                  processes or  screens  you  create  by  invoking  an
  13718.                  external utility  or application.   When  Hamilton C
  13719.                  shell starts  up it looks for the ones shown here to
  13720.                  be defined  in the  environment it  inherits.  HOME,
  13721.                  PATH and  SHELL  are special: if they're not already
  13722.                  defined, then the shell creates them.
  13723.  
  13724.                  On Windows NT, environmental variables are not case-
  13725.                  sensitive, so, e.g., Path and PATH refer to the same
  13726.                  thing.
  13727.  
  13728.  
  13729.  
  13730.  
  13731.  
  13732.  
  13733.  
  13734.  
  13735.  
  13736.  
  13737.  
  13738.  
  13739.  
  13740.  
  13741.  
  13742.  
  13743.  
  13744.  
  13745.  
  13746.  
  13747.  
  13748.  
  13749.  
  13750.                                      Page 215
  13751.  
  13752.      Predefined Variables
  13753.  
  13754.  
  13755.             
  13756.             
  13757.  
  13758.  
  13759.                         Predefined Process-Wide Variables
  13760.  
  13761.  
  13762.             Name          Default  Use                                  
  13763.  
  13764.             $                      A synonym for the processid
  13765.                                    variable.
  13766.  
  13767.             bsdhistory          0  By default, ``!!'' is the
  13768.                                    immediately preceding command and
  13769.                                    ``!-1'' is the one before that.
  13770.                                    Setting bsdhistory = 1 makes them
  13771.                                    the same.
  13772.  
  13773.             cdpath           null  Same as the CDPATH environmental
  13774.                                    variable, broken into words.
  13775.  
  13776.             escapesym           ^  Character to be interpreted as a
  13777.                                    literal escape character.
  13778.  
  13779.             histchars          !%  Characters which introduce long-
  13780.                                    form and short-form history
  13781.                                    references, respectively.
  13782.  
  13783.             home                   Same as the HOME environmental
  13784.                                    variable.
  13785.  
  13786.             NTVersion              Build number of the NT system on
  13787.                                    which the shell is running, e.g.,
  13788.                                    340 for the October Beta.  (Not
  13789.                                    defined on OS/2.)
  13790.  
  13791.             os2version             Version number of the OS/2 system
  13792.                                    on which the shell is running.
  13793.                                    (Not defined on NT.)
  13794.  
  13795.             path                   Same as the PATH environmental
  13796.                                    variable, broken into words.
  13797.  
  13798.             processid              The unique process ID assigned by
  13799.                                    the OS/2 or NT kernel to this copy
  13800.                                    of the C shell.
  13801.  
  13802.             prompt1    $@ $CDISK%  Same as PROMPT1 environmental
  13803.                                    variable.
  13804.  
  13805.             prompt2    $@ $CDISK?  Same as PROMPT2 environmental
  13806.                                    variable.
  13807.  
  13808.  
  13809.  
  13810.  
  13811.  
  13812.                                      Page 216
  13813.  
  13814.                                                          Predefined Variables
  13815.  
  13816.  
  13817.             savehist            0  Save the history contents into
  13818.                                    history.csh in the home directory.
  13819.  
  13820.             shell                  Same as SHELL environmental
  13821.                                    variable.
  13822.  
  13823.             WinVersion             Version number of the Windows API
  13824.                                    on which the shell is running,
  13825.                                    e.g., 3.1 for the October Beta.
  13826.                                    (Not defined on OS/2.)
  13827.  
  13828.  
  13829.                  Any user-defined  variables (with  the exception  of
  13830.                  the  parameter   names  of   a  procedure  or  those
  13831.                  variables explicitly  defined as  local) are  shared
  13832.                  globally by all threads.
  13833.  
  13834.  
  13835.  
  13836.  
  13837.  
  13838.  
  13839.  
  13840.  
  13841.  
  13842.  
  13843.  
  13844.  
  13845.  
  13846.  
  13847.  
  13848.  
  13849.  
  13850.  
  13851.  
  13852.  
  13853.  
  13854.  
  13855.  
  13856.  
  13857.  
  13858.  
  13859.  
  13860.  
  13861.  
  13862.  
  13863.  
  13864.  
  13865.  
  13866.  
  13867.  
  13868.  
  13869.  
  13870.  
  13871.  
  13872.  
  13873.  
  13874.                                      Page 217
  13875.  
  13876.      Predefined Variables
  13877.  
  13878.  
  13879.             
  13880.  
  13881.  
  13882.                          Predefined Per-Thread Variables
  13883.  
  13884.  
  13885.             Inherited from the parent thread:
  13886.  
  13887.             Name          Default  Use                                  
  13888.  
  13889.             argv                   Any argument words passed to the
  13890.                                    shell or to a .csh batch file.
  13891.  
  13892.             bsdargv             0  If set, $argv[0] contains the name
  13893.                                    of the script, just as it would
  13894.                                    under the original Berkeley C
  13895.                                    shell; by default, $argv[0] is the
  13896.                                    first argument word.
  13897.  
  13898.             cdhome              0  If set, ``cd'' with no argument is
  13899.                                    the same as ``cd $home''; default
  13900.                                    is to simply print the current
  13901.                                    directory name.
  13902.  
  13903.             cdisk                  Current disk, not including colon.
  13904.  
  13905.             CDISK                  Same as cdisk, but in upper case.
  13906.  
  13907.             chgdisk             0  If set, cd automatically does a
  13908.                                    DosSelectDisk if the path is on
  13909.                                    another disk.
  13910.  
  13911.             cwd                    Full pathname of the current
  13912.                                    directory.
  13913.  
  13914.             gotowindow         50  Number of statements a goto can
  13915.                                    jump over (when not inside a
  13916.                                    nested block) without being
  13917.                                    considered an error.
  13918.  
  13919.             nohashing           0  Determine how/whether path hashing
  13920.                                    is done:  0 means full path
  13921.                                    hashing of the directories on the
  13922.                                    search path; 1 means turn off
  13923.                                    hashing completely; 2 means hash
  13924.                                    only the directories which do not
  13925.                                    depend on the setting of the
  13926.                                    current directory.
  13927.  
  13928.             noclobber           0  If True, don't allow redirection
  13929.                                    to overwrite an existing file
  13930.                                    unless the ``!'' override is
  13931.                                    given.
  13932.  
  13933.  
  13934.  
  13935.  
  13936.                                      Page 218
  13937.  
  13938.                                                          Predefined Variables
  13939.  
  13940.  
  13941.             noglob                 A synonym for the nowild variable.
  13942.  
  13943.             nonohidden          0  Determine whether wildcarding will
  13944.                                    match against hidden files:  0
  13945.                                    means don't match hidden files; 1
  13946.                                    means hidden files will be found.
  13947.  
  13948.             nonomatch           0  Determine the response to a
  13949.                                    wildcard that doesn't match
  13950.                                    anything:  0 means it's an error;
  13951.                                    1 means pass it through to the
  13952.                                    application; 2 means simply
  13953.                                    discard it.
  13954.  
  13955.  
  13956.  
  13957.  
  13958.  
  13959.  
  13960.  
  13961.  
  13962.  
  13963.  
  13964.  
  13965.  
  13966.  
  13967.  
  13968.  
  13969.  
  13970.  
  13971.  
  13972.  
  13973.  
  13974.  
  13975.  
  13976.  
  13977.  
  13978.  
  13979.  
  13980.  
  13981.  
  13982.  
  13983.  
  13984.  
  13985.  
  13986.  
  13987.  
  13988.  
  13989.  
  13990.  
  13991.  
  13992.  
  13993.  
  13994.  
  13995.  
  13996.  
  13997.  
  13998.                                      Page 219
  13999.  
  14000.      Predefined Variables
  14001.  
  14002.  
  14003.             
  14004.  
  14005.  
  14006.                          Predefined Per-Thread Variables
  14007.  
  14008.  
  14009.             Inherited from the parent thread:
  14010.  
  14011.             Name          Default  Use                                  
  14012.  
  14013.             nonovar             0  Determine the response to a
  14014.                                    reference to a non-existent
  14015.                                    variable, procedure or alias.
  14016.                                    Same encoding as nonomatch.
  14017.  
  14018.             nowild              0  If True, turn off filename
  14019.                                    wildcarding.
  14020.  
  14021.             nullwords           0  Determines whether an array index
  14022.                                    off the end of a list is an error
  14023.                                    (0) or returns a null word (1).
  14024.  
  14025.             precision           6  Number of decimal places to print
  14026.                                    when displaying floating point
  14027.                                    values.
  14028.  
  14029.             tailstatus          0  Determines whether the status
  14030.                                    variable will reflect the reflect
  14031.                                    the return code from the leftmost
  14032.                                    or rightmost stage of a pipeline:
  14033.                                    0 means leftmost; 1 means
  14034.                                    rightmost.
  14035.  
  14036.             verbose             0  If True, print out all available
  14037.                                    information when reporting errors.
  14038.  
  14039.  
  14040.                  Each new  thread is  initialized  with  default  on-
  14041.                  interrupt  processing  (a  forced  exit),  and  null
  14042.                  search and replace strings.  echoinput, ignoreerrors
  14043.                  and interactive  are initialized for the main thread
  14044.                  based on command-line options.
  14045.  
  14046.                  Each thread  also has  its own independent notion of
  14047.                  current  disk  and  current  directories,  initially
  14048.                  inherited from its parent.
  14049.  
  14050.  
  14051.  
  14052.  
  14053.  
  14054.  
  14055.  
  14056.  
  14057.  
  14058.  
  14059.  
  14060.                                      Page 220
  14061.  
  14062.                                                          Predefined Variables
  14063.  
  14064.  
  14065.  
  14066.                          Predefined Per-Thread Variables
  14067.  
  14068.  
  14069.             Always initialized  to the  default for  each  new  child
  14070.             thread:
  14071.  
  14072.             Name          Default  Use                                  
  14073.  
  14074.             *                      A synonym for the argv variable.
  14075.  
  14076.             <                      A synonym for the getline
  14077.                                    variable.
  14078.  
  14079.             @                      A synonym for the stmtnumber
  14080.                                    variable.
  14081.  
  14082.             child               0  Identification number of the last
  14083.                                    child process spawned.
  14084.  
  14085.             echoinput           0  Copy the input to stdout as it's
  14086.                                    read.
  14087.  
  14088.             eofgetline          0  Pseudo-variable to indicate if the
  14089.                                    last reference to getline
  14090.                                    encountered an end-of-file
  14091.                                    condition.
  14092.  
  14093.             getchar                Read one character from stdin
  14094.                                    without echoing.  If stdin is tied
  14095.                                    to the keyboard, outboard keys are
  14096.                                    returned as a two-character
  14097.                                    string.
  14098.  
  14099.             getline                Read one line from stdin pseudo-
  14100.                                    variable.  If stdin is tied to the
  14101.                                    keyboard, keystrokes are echoed as
  14102.                                    they're typed.
  14103.  
  14104.             history             0  Number of statements to remember
  14105.                                    on the history list; 0 turns off
  14106.                                    the history mechanism.  (If the
  14107.                                    thread is interactive, history is
  14108.                                    automatically set to 100.)
  14109.  
  14110.             ignoreeof           0  If True, don't exit at EOF on
  14111.                                    stdin; insist on an exit command.
  14112.  
  14113.             ignoreerrors        0  Determine whether execution should
  14114.                                    continue if an error occurs:  0
  14115.                                    means the thread exits; 1 (the
  14116.                                    default for an interactive thread)
  14117.                                    means exit from loops or
  14118.                                    procedures and try to read a new
  14119.  
  14120.  
  14121.  
  14122.                                      Page 221
  14123.  
  14124.      Predefined Variables
  14125.  
  14126.  
  14127.                                    command; 2 means ignore all
  14128.                                    errors.
  14129.  
  14130.             ignorestatus        1  If True, a non-zero status code
  14131.                                    from a child process is ignored.
  14132.                                    Otherwise, it's an error.
  14133.  
  14134.             interactive         0  If True, prompt for input.
  14135.  
  14136.             irqmask             0  Determines whether interrupts are
  14137.                                    enabled (0), deferred until the
  14138.                                    mask is cleared again (1) or
  14139.                                    ignored (2).
  14140.  
  14141.             scriptname             Name of the C shell script file
  14142.                                    being executed, if any.
  14143.  
  14144.  
  14145.  
  14146.  
  14147.  
  14148.  
  14149.  
  14150.  
  14151.  
  14152.  
  14153.  
  14154.  
  14155.  
  14156.  
  14157.  
  14158.  
  14159.  
  14160.  
  14161.  
  14162.  
  14163.  
  14164.  
  14165.  
  14166.  
  14167.  
  14168.  
  14169.  
  14170.  
  14171.  
  14172.  
  14173.  
  14174.  
  14175.  
  14176.  
  14177.  
  14178.  
  14179.  
  14180.  
  14181.  
  14182.  
  14183.  
  14184.                                      Page 222
  14185.  
  14186.                                                          Predefined Variables
  14187.  
  14188.  
  14189.  
  14190.                          Predefined Per-Thread Variables
  14191.  
  14192.  
  14193.             Always initialized  to the  default for  each  new  child
  14194.             thread:
  14195.  
  14196.             Name          Default  Use                                  
  14197.  
  14198.             status              0  Exit code of the last child
  14199.                                    process.
  14200.  
  14201.             stmtnumber          1  Autoincremented statement number
  14202.                                    used with the history list and in
  14203.                                    prompting.
  14204.  
  14205.             threadid               Thread id of the currently
  14206.                                    executing thread.
  14207.  
  14208.  
  14209.  
  14210.  
  14211.  
  14212.  
  14213.  
  14214.  
  14215.  
  14216.  
  14217.  
  14218.  
  14219.  
  14220.  
  14221.  
  14222.  
  14223.  
  14224.  
  14225.  
  14226.  
  14227.  
  14228.  
  14229.  
  14230.  
  14231.  
  14232.  
  14233.  
  14234.  
  14235.  
  14236.  
  14237.  
  14238.  
  14239.  
  14240.  
  14241.  
  14242.  
  14243.  
  14244.  
  14245.  
  14246.                                      Page 223
  14247.  
  14248.      Predefined Variables
  14249.  
  14250.  
  14251.  
  14252.                               Predefined Variables
  14253.  
  14254.                                  Sorted by Name
  14255.  
  14256.  
  14257.             Legend for this table:
  14258.  
  14259.               COURIER A setenv environmental variable.  Environmental
  14260.                       variables are  passed to any child processes or
  14261.                       screens you  create  by  invoking  an  external
  14262.                       utility or  application.  When Hamilton C shell
  14263.                       starts up  it looks  for the ones shown here to
  14264.                       be defined  in the  environment it inherits; if
  14265.                       they're not  already defined, the shell creates
  14266.                       them.
  14267.  
  14268.               bold    A set  variable shared  by all threads:  if one
  14269.                       makes a change, all will see it.
  14270.  
  14271.               normal  Each thread  gets its  own copy but the initial
  14272.                       value is inherited from its parent.
  14273.  
  14274.               italics Each  thread   gets  its   own  copy   but  the
  14275.                       initialization is always to a defined value.
  14276.  
  14277.             Name          Default  Use                                  
  14278.  
  14279.             $                      A synonym for the processid
  14280.                                    variable.
  14281.  
  14282.             *                      A synonym for the argv variable.
  14283.  
  14284.             <                      A synonym for the getline
  14285.                                    variable.
  14286.  
  14287.             @                      A synonym for the stmtnumber
  14288.                                    variable.
  14289.  
  14290.             ADDITIONSBright Green  Lines added found by diff.
  14291.  
  14292.             argv                   Any argument words passed to the
  14293.                                    shell or to a .csh batch file.
  14294.  
  14295.             bsdargv             0  If set, $argv[0] contains the name
  14296.                                    of the script, just as it would
  14297.                                    under the original Berkeley C
  14298.                                    shell; by default, $argv[0] is the
  14299.                                    first argument word.
  14300.  
  14301.             bsdhistory          0  By default, ``!!'' is the
  14302.                                    immediately preceding command and
  14303.                                    ``!-1'' is the one before that.
  14304.  
  14305.  
  14306.  
  14307.  
  14308.                                      Page 224
  14309.  
  14310.                                                          Predefined Variables
  14311.  
  14312.  
  14313.                                    Setting bsdhistory = 1 makes them
  14314.                                    the same.
  14315.  
  14316.             cdhome              0  If set, ``cd'' with no argument is
  14317.                                    the same as ``cd $home''; default
  14318.                                    is to simply print the current
  14319.                                    directory name.
  14320.  
  14321.             cdisk                  Current disk, not including colon.
  14322.  
  14323.             CDISK                  Same as cdisk, but in upper case.
  14324.  
  14325.             CDPATH                 List of directories to search for
  14326.                                    the subdirectory specified as the
  14327.                                    new current directory.
  14328.  
  14329.  
  14330.  
  14331.  
  14332.  
  14333.  
  14334.  
  14335.  
  14336.  
  14337.  
  14338.  
  14339.  
  14340.  
  14341.  
  14342.  
  14343.  
  14344.  
  14345.  
  14346.  
  14347.  
  14348.  
  14349.  
  14350.  
  14351.  
  14352.  
  14353.  
  14354.  
  14355.  
  14356.  
  14357.  
  14358.  
  14359.  
  14360.  
  14361.  
  14362.  
  14363.  
  14364.  
  14365.  
  14366.  
  14367.  
  14368.  
  14369.  
  14370.                                      Page 225
  14371.  
  14372.      Predefined Variables
  14373.  
  14374.  
  14375.  
  14376.                               Predefined Variables
  14377.  
  14378.                                  Sorted by Name
  14379.  
  14380.  
  14381.             Name          Default  Use                                  
  14382.  
  14383.             cdpath           null  Same as the CDPATH environmental
  14384.                                    variable, broken into words.
  14385.  
  14386.             chgdisk             0  If set, cd automatically does a
  14387.                                    DosSelectDisk if the path is on
  14388.                                    another disk.
  14389.  
  14390.             child               0  Identification number of the last
  14391.                                    child process spawned.
  14392.  
  14393.             COLORS White on Black  Normal screen colors.
  14394.  
  14395.             COMSPEC                Usually, this is the pathname of
  14396.                                    cmd.exe.  If you set it to point
  14397.                                    to the C shell, e.g., so other
  14398.                                    programs will invoke the C shell
  14399.                                    rather than cmd.exe, the C shell
  14400.                                    will try to look through the
  14401.                                    search path for cmd.exe if it
  14402.                                    needs to run a .cmd file.
  14403.  
  14404.             CSHOPTIONS             Default set of command line
  14405.                                    options to be pasted ahead of any
  14406.                                    other command line options passed
  14407.                                    to csh.exe.
  14408.  
  14409.             cwd                    Full pathname of the current
  14410.                                    directory.
  14411.  
  14412.             DELETIONS  Bright Red  Lines deleted found by diff.
  14413.  
  14414.             DIRECTORIES    Bright  Directories listed by ls.
  14415.  
  14416.             DUPLICATES      Green  When filename completion matches
  14417.                                    matches more than one name.
  14418.  
  14419.             DRIVEMASK              Used by du.exe, pwd.exe and vl.exe
  14420.                                    to limit the default list of
  14421.                                    drives it will report on.  Written
  14422.                                    as a list of alphabetic characters
  14423.                                    representing the drives you want
  14424.                                    listed; ranges are allowed.  If
  14425.                                    you don't define this variable,
  14426.                                    all drives beginning with C: are
  14427.                                    normally reported.
  14428.  
  14429.  
  14430.  
  14431.  
  14432.                                      Page 226
  14433.  
  14434.                                                          Predefined Variables
  14435.  
  14436.  
  14437.             echoinput           0  Copy the input to stdout as it's
  14438.                                    read.
  14439.  
  14440.             eofgetline          0  Pseudo-variable to indicate if the
  14441.                                    last reference to getline
  14442.                                    encountered an end-of-file
  14443.                                    condition.
  14444.  
  14445.             ESCAPESYM           ^  Character to be interpreted as a
  14446.                                    literal escape character.  Placed
  14447.                                    in the environment only if it is
  14448.                                    not the default circumflex.
  14449.  
  14450.  
  14451.  
  14452.  
  14453.  
  14454.  
  14455.  
  14456.  
  14457.  
  14458.  
  14459.  
  14460.  
  14461.  
  14462.  
  14463.  
  14464.  
  14465.  
  14466.  
  14467.  
  14468.  
  14469.  
  14470.  
  14471.  
  14472.  
  14473.  
  14474.  
  14475.  
  14476.  
  14477.  
  14478.  
  14479.  
  14480.  
  14481.  
  14482.  
  14483.  
  14484.  
  14485.  
  14486.  
  14487.  
  14488.  
  14489.  
  14490.  
  14491.  
  14492.  
  14493.  
  14494.                                      Page 227
  14495.  
  14496.      Predefined Variables
  14497.  
  14498.  
  14499.  
  14500.                               Predefined Variables
  14501.  
  14502.                                  Sorted by Name
  14503.  
  14504.  
  14505.             Name          Default  Use                                  
  14506.  
  14507.             escapesym           ^  Same as the ESCAPESYM
  14508.                                    environmental variable.
  14509.  
  14510.             FOREIGNFILESBright Red Filetypes in a tar file that have
  14511.                                    no counterpart on OS/2 or NT.
  14512.  
  14513.             getchar                Read one character from stdin
  14514.                                    without echoing.  If stdin is tied
  14515.                                    to the keyboard, outboard keys are
  14516.                                    returned as a two-character
  14517.                                    string.
  14518.  
  14519.             getline                Read one line from stdin pseudo-
  14520.                                    variable.  If stdin is tied to the
  14521.                                    keyboard, keystrokes are echoed as
  14522.                                    they're typed.
  14523.  
  14524.             gotowindow         50  Number of statements a goto can
  14525.                                    jump over (when not inside a
  14526.                                    nested block) without being
  14527.                                    considered an error.
  14528.  
  14529.             HIGHLIGHT      Bright  Current disk or directory.
  14530.  
  14531.             histchars          !%  Characters which introduce long-
  14532.                                    form and short-form history
  14533.                                    references, respectively.
  14534.  
  14535.             history             0  Number of statements to remember
  14536.                                    on the history list; 0 turns off
  14537.                                    the history mechanism.  (If the
  14538.                                    thread is interactive, history is
  14539.                                    automatically set to 100.)
  14540.  
  14541.             HOME                   Home directory (default is the
  14542.                                    initial current directory.)
  14543.  
  14544.             home                   Same as the HOME environmental
  14545.                                    variable.
  14546.  
  14547.             ignoreeof           0  If True, don't exit at EOF on
  14548.                                    stdin; insist on an exit command.
  14549.  
  14550.             ignoreerrors        0  Determine whether execution should
  14551.                                    continue if an error occurs:  0
  14552.                                    means the thread exits; 1 (the
  14553.  
  14554.  
  14555.  
  14556.                                      Page 228
  14557.  
  14558.                                                          Predefined Variables
  14559.  
  14560.  
  14561.                                    default for an interactive thread)
  14562.                                    means exit from loops or
  14563.                                    procedures and try to read a new
  14564.                                    command; 2 means ignore all
  14565.                                    errors.
  14566.  
  14567.             ignorestatus        1  If True, a non-zero status code
  14568.                                    from a child process is ignored.
  14569.                                    Otherwise, it's an error.
  14570.  
  14571.             interactive         0  If True, prompt for input.
  14572.  
  14573.  
  14574.  
  14575.  
  14576.  
  14577.  
  14578.  
  14579.  
  14580.  
  14581.  
  14582.  
  14583.  
  14584.  
  14585.  
  14586.  
  14587.  
  14588.  
  14589.  
  14590.  
  14591.  
  14592.  
  14593.  
  14594.  
  14595.  
  14596.  
  14597.  
  14598.  
  14599.  
  14600.  
  14601.  
  14602.  
  14603.  
  14604.  
  14605.  
  14606.  
  14607.  
  14608.  
  14609.  
  14610.  
  14611.  
  14612.  
  14613.  
  14614.  
  14615.  
  14616.  
  14617.  
  14618.                                      Page 229
  14619.  
  14620.      Predefined Variables
  14621.  
  14622.  
  14623.  
  14624.                               Predefined Variables
  14625.  
  14626.                                  Sorted by Name
  14627.  
  14628.  
  14629.             Name          Default  Use                                  
  14630.  
  14631.             irqmask             0  Determines whether interrupts are
  14632.                                    enabled (0), deferred until the
  14633.                                    mask is cleared again (1) or
  14634.                                    ignored (2).
  14635.  
  14636.             LSOPTIONS              Default set of command line
  14637.                                    options to be pasted ahead of any
  14638.                                    other command line options passed
  14639.                                    to ls.exe.
  14640.  
  14641.             MATCHFAIL  Bright Red  When filename or command
  14642.                                    completion doesn't match anything.
  14643.  
  14644.             MIXEDCASEDRIVES        List of drives and UNC names for
  14645.                                    which ls.exe,  pwd.exe,
  14646.                                    wildcarding and the fullname and
  14647.                                    current directory functions
  14648.                                    should report filenames in mixed
  14649.                                    case rather than all lower case.
  14650.  
  14651.             MOREEOF         Green  End or Top of File in more.
  14652.  
  14653.             MOREERRORBright Yellow Unrecognizable command to more.
  14654.  
  14655.             MOREFILLIN      White  User response to more prompt.
  14656.  
  14657.             MOREPROMPT      Green  Prompt line in more.
  14658.  
  14659.             MORETOPMEMBright Yellow                                     
  14660.                                    Top of Memory message from more.
  14661.  
  14662.             NETWORKBUG             If NETWORKBUG = 1, the shell and
  14663.                                    all the utilities will read
  14664.                                    directory entries only one-at-a-
  14665.                                    time as a workaround for a
  14666.                                    networking bug.  (Not used on NT.)
  14667.  
  14668.             nohashing           0  Determine how/whether path hashing
  14669.                                    is done:  0 means full path
  14670.                                    hashing of the directories on the
  14671.                                    search path; 1 means turn off
  14672.                                    hashing completely; 2 means hash
  14673.                                    only the directories which do not
  14674.                                    depend on the setting of the
  14675.                                    current directory.
  14676.  
  14677.  
  14678.  
  14679.  
  14680.                                      Page 230
  14681.  
  14682.                                                          Predefined Variables
  14683.  
  14684.  
  14685.             noclobber           0  If True, don't allow redirection
  14686.                                    to overwrite an existing file
  14687.                                    unless the ``!'' override is
  14688.                                    given.
  14689.  
  14690.             noglob                 A synonym for the nowild variable.
  14691.  
  14692.             nonohidden          0  Determine whether wildcarding will
  14693.                                    match against hidden files:  0
  14694.                                    means don't match hidden files; 1
  14695.                                    means hidden files will be found.
  14696.  
  14697.  
  14698.  
  14699.  
  14700.  
  14701.  
  14702.  
  14703.  
  14704.  
  14705.  
  14706.  
  14707.  
  14708.  
  14709.  
  14710.  
  14711.  
  14712.  
  14713.  
  14714.  
  14715.  
  14716.  
  14717.  
  14718.  
  14719.  
  14720.  
  14721.  
  14722.  
  14723.  
  14724.  
  14725.  
  14726.  
  14727.  
  14728.  
  14729.  
  14730.  
  14731.  
  14732.  
  14733.  
  14734.  
  14735.  
  14736.  
  14737.  
  14738.  
  14739.  
  14740.  
  14741.  
  14742.                                      Page 231
  14743.  
  14744.      Predefined Variables
  14745.  
  14746.  
  14747.  
  14748.                               Predefined Variables
  14749.  
  14750.                                  Sorted by Name
  14751.  
  14752.  
  14753.             Name          Default  Use                                  
  14754.  
  14755.             nonomatch           0  Determine the response to a
  14756.                                    wildcard that doesn't match
  14757.                                    anything:  0 means it's an error;
  14758.                                    1 means pass it through to the
  14759.                                    application; 2 means simply
  14760.                                    discard it.
  14761.  
  14762.             nonovar             0  Determine the response to a non-
  14763.                                    existent variable, procedure or
  14764.                                    alias.  Same encoding as
  14765.                                    nonomatch.
  14766.  
  14767.             nowild              0  If True, turn off filename
  14768.                                    wildcarding.
  14769.  
  14770.             NTVersion              Build number of the NT system on
  14771.                                    which the shell is running, e.g.,
  14772.                                    340 for the October Beta.  (Not
  14773.                                    defined on OS/2.)
  14774.  
  14775.             nullwords           0  Determines whether an array index
  14776.                                    off the end of a list is an error
  14777.                                    (0) or returns a null word (1).
  14778.  
  14779.             os2version             Version number of the OS/2 system
  14780.                                    on which the shell is running.
  14781.                                    (Not defined on NT.)
  14782.  
  14783.             PATH                   Search path for executable files.
  14784.  
  14785.             path                   Same as the PATH environmental
  14786.                                    variable, broken into words.
  14787.  
  14788.             precision           6  Number of decimal places to print
  14789.                                    when displaying floating point
  14790.                                    values.
  14791.  
  14792.             processid              The unique process ID assigned by
  14793.                                    the OS/2 or NT kernel to this copy
  14794.                                    of the C shell.
  14795.  
  14796.             PROMPT1    $@ $CDISK%  Primary command prompt template.
  14797.  
  14798.             prompt1                Same as the PROMPT1 environmental
  14799.                                    variable.
  14800.  
  14801.  
  14802.  
  14803.  
  14804.                                      Page 232
  14805.  
  14806.                                                          Predefined Variables
  14807.  
  14808.  
  14809.             PROMPT2    $@ $CDISK?  Continuation line prompt template.
  14810.  
  14811.             prompt2                Same as the PROMPT2 environmental
  14812.                                    variable.
  14813.  
  14814.             RADIX              16  Default radix used by more.exe
  14815.                                    when displaying binary data.
  14816.  
  14817.             savehist            0  Save the history contents into
  14818.                                    history.csh in the home directory.
  14819.  
  14820.             scriptname             Name of the C shell script file
  14821.                                    being executed, if any.
  14822.  
  14823.             SHELL                  Always set to the pathname of the
  14824.                                    Hamilton C shell csh.exe file.
  14825.  
  14826.  
  14827.  
  14828.  
  14829.  
  14830.  
  14831.  
  14832.  
  14833.  
  14834.  
  14835.  
  14836.  
  14837.  
  14838.  
  14839.  
  14840.  
  14841.  
  14842.  
  14843.  
  14844.  
  14845.  
  14846.  
  14847.  
  14848.  
  14849.  
  14850.  
  14851.  
  14852.  
  14853.  
  14854.  
  14855.  
  14856.  
  14857.  
  14858.  
  14859.  
  14860.  
  14861.  
  14862.  
  14863.  
  14864.  
  14865.  
  14866.                                      Page 233
  14867.  
  14868.      Predefined Variables
  14869.  
  14870.  
  14871.  
  14872.                               Predefined Variables
  14873.  
  14874.                                  Sorted by Name
  14875.  
  14876.  
  14877.             Name          Default  Use                                  
  14878.  
  14879.             shell                  Same as the SHELL environmental
  14880.                                    variable.
  14881.  
  14882.             status              0  Exit code of the last child
  14883.                                    process.
  14884.  
  14885.             stmtnumber          1  Autoincremented statement number
  14886.                                    used with the history list and in
  14887.                                    prompting.
  14888.  
  14889.             SWITCHCHARS        -/  Characters that can be used as
  14890.                                    option introducers for the shell
  14891.                                    and utilities.
  14892.  
  14893.             SYSTEMDIRSBright Green Used by ls.exe for directories
  14894.                                    with the System bit on.
  14895.  
  14896.             SYSTEMFILES     Green  Used by ls.exe for files with the
  14897.                                    System bit on.
  14898.  
  14899.             TABS                8  Used by more.exe to tell it how
  14900.                                    many character positions there are
  14901.                                    between tab stops.
  14902.  
  14903.             tailstatus          0  Determines whether the status
  14904.                                    variable will reflect the reflect
  14905.                                    the return code from the leftmost
  14906.                                    or rightmost stage of a pipeline:
  14907.                                    0 means leftmost; 1 means
  14908.                                    rightmost.
  14909.  
  14910.             TAPE        \\.\tape0  Used by mt.exe under Windows NT to
  14911.                                    specify the pathname of the
  14912.                                    default tape drive.
  14913.  
  14914.             threadid               Thread id of the currently
  14915.                                    executing thread.
  14916.  
  14917.             TZ                     Used by tar.exe under OS/2 to tell
  14918.                                    it how to convert between local
  14919.                                    time and GMT.  (Under Windows NT,
  14920.                                    the system keeps track of the
  14921.                                    difference between local time and
  14922.                                    GMT, so the TZ variable is not
  14923.                                    needed.)  The TZ variable should
  14924.                                    be in the form of a three-letter
  14925.  
  14926.  
  14927.  
  14928.                                      Page 234
  14929.  
  14930.                                                          Predefined Variables
  14931.  
  14932.  
  14933.                                    timezone, e.g., EST, followed by a
  14934.                                    signed number giving the
  14935.                                    difference in hours between GMT
  14936.                                    and local time, followed by an
  14937.                                    optional daylight savings
  14938.                                    timezone.  Examples are EST5EDT in
  14939.                                    New York or PST8PDT in California.
  14940.  
  14941.             verbose             0  If True, print out all available
  14942.                                    information when reporting errors.
  14943.  
  14944.             WinVersion             Version number of the Windows API
  14945.                                    on which the shell is running,
  14946.                                    e.g., 3.1 for the October Beta.
  14947.                                    (Not defined on OS/2.)
  14948.  
  14949.  
  14950.  
  14951.  
  14952.  
  14953.  
  14954.  
  14955.  
  14956.  
  14957.  
  14958.  
  14959.  
  14960.  
  14961.  
  14962.  
  14963.  
  14964.  
  14965.  
  14966.  
  14967.  
  14968.  
  14969.  
  14970.  
  14971.  
  14972.  
  14973.  
  14974.  
  14975.  
  14976.  
  14977.  
  14978.  
  14979.  
  14980.  
  14981.  
  14982.  
  14983.  
  14984.  
  14985.  
  14986.  
  14987.  
  14988.  
  14989.  
  14990.                                      Page 235
  14991.  
  14992.      Built-in Procedures
  14993.  
  14994.  
  14995.  
  14996.                                         
  14997.  
  14998.  
  14999.  
  15000.  
  15001.                                Built-in Procedures
  15002.  
  15003.  
  15004.               Name                        Function                   
  15005.  
  15006.  
  15007.             Filename Functions:
  15008.  
  15009.               childpath(p, c)             Test whether filename c
  15010.                                           could be in a subdirectory
  15011.                                           of p.  (Does not test for
  15012.                                           actual existence of either
  15013.                                           c or p.)
  15014.  
  15015.               driveno(p)                  Drive number implied by
  15016.                                           pathname p.
  15017.  
  15018.               fullpath(p)                 Fully resolve pathname p.
  15019.  
  15020.               samepath(a, b)              Test whether two filenames,
  15021.                                           a and b, point to the same
  15022.                                           file.
  15023.  
  15024.  
  15025.             Math Functions:
  15026.  
  15027.               abs(x)                      Absolute value
  15028.  
  15029.               acos(x)   asin(x)   atan(x)   cos(x)   sin(x)   tan(x)
  15030.                                           Trigonometric functions
  15031.  
  15032.               cosh(x)   sinh(x)   tanh(x) Hyperbolic functions
  15033.  
  15034.               ceil(x)                     Ceiling (lowest integer >=
  15035.                                           x)
  15036.  
  15037.               exp(x)   log(x)   log2(x)   log10(x)  Exponential and
  15038.                                           logarithmic functions
  15039.  
  15040.               floor(x)                    Floor (highest integer <=
  15041.                                           x)
  15042.  
  15043.               round(x)                    floor(x + 0.5)
  15044.  
  15045.               sqrt(x)                     Square root
  15046.  
  15047.  
  15048.  
  15049.  
  15050.  
  15051.  
  15052.                                      Page 236
  15053.  
  15054.                                                           Built-in Procedures
  15055.  
  15056.  
  15057.  
  15058.                                Built-in Procedures
  15059.  
  15060.  
  15061.               Name                        Function                   
  15062.  
  15063.  
  15064.             String Functions:
  15065.  
  15066.               ansi(color)                 Return an ANSI escape
  15067.                                           sequence which will produce
  15068.                                           the specified screen
  15069.                                           colors.  If the argument is
  15070.                                           ambiguous, e.g., simply
  15071.                                           ``bright,'' it's taken as a
  15072.                                           modification of the default
  15073.                                           colors specified by the
  15074.                                           COLORS variable.
  15075.  
  15076.               char(i)                     Return the character
  15077.                                           corresponding to the
  15078.                                           numeric value i.
  15079.  
  15080.               code(c)                     Return the numeric encoding
  15081.                                           of the character c.
  15082.  
  15083.               concat(a, b, ...)           Concatenation of a series
  15084.                                           of strings.
  15085.  
  15086.               isinteger(x)                Test whether x is an
  15087.                                           integer.  (Remember that
  15088.                                           null strings and strings
  15089.                                           consisting only of white
  15090.                                           space are considered equal
  15091.                                           to 0.)
  15092.  
  15093.               isnumber(x)                 Test whether x is a number.
  15094.  
  15095.               printf(fmt, ...)            Perform C language-style
  15096.                                           print formatting, returning
  15097.                                           the result as a string.
  15098.                                           (See table of format
  15099.                                           conversions on following
  15100.                                           page.)
  15101.  
  15102.               reverse(s)                  Reverse the order of
  15103.                                           characters in s.
  15104.  
  15105.               strindex(a, b)              Return the position in a of
  15106.                                           the first occurrence of b.
  15107.                                           (0 means b was not found.)
  15108.  
  15109.               strlen(s)                   Number of characters in s,
  15110.                                           represented as a string
  15111.  
  15112.  
  15113.  
  15114.                                      Page 237
  15115.  
  15116.      Built-in Procedures
  15117.  
  15118.  
  15119.               substr(s, b, i)             Substring of length i
  15120.                                           beginning at b-th character
  15121.                                           of s.  (i = 0 means ``rest
  15122.                                           of s'')
  15123.  
  15124.               upper(s)   lower(s)         Translate a string to all
  15125.                                           upper- or all lower-case
  15126.  
  15127.  
  15128.  
  15129.  
  15130.  
  15131.  
  15132.  
  15133.  
  15134.  
  15135.  
  15136.  
  15137.  
  15138.  
  15139.  
  15140.  
  15141.  
  15142.  
  15143.  
  15144.  
  15145.  
  15146.  
  15147.  
  15148.  
  15149.  
  15150.  
  15151.  
  15152.  
  15153.  
  15154.  
  15155.  
  15156.  
  15157.  
  15158.  
  15159.  
  15160.  
  15161.  
  15162.  
  15163.  
  15164.  
  15165.  
  15166.  
  15167.  
  15168.  
  15169.  
  15170.  
  15171.  
  15172.  
  15173.  
  15174.  
  15175.  
  15176.                                      Page 238
  15177.  
  15178.                                                           Built-in Procedures
  15179.  
  15180.  
  15181.  
  15182.                                         
  15183.  
  15184.  
  15185.  
  15186.  
  15187.                             Printf Format Directives
  15188.  
  15189.  
  15190.                    These argument formats are recognized by printf:
  15191.  
  15192.                       %c        Single character.
  15193.                       %d        Decimal number.
  15194.                       %e        [-]d.dddddde[+-]ddd
  15195.                       %f        [-]ddd.dddddd
  15196.                       %g        %e or %f formatting, whichever is
  15197.                                 shorter.
  15198.                       %o        Unsigned octal number.
  15199.                       %s        String.
  15200.                       %x        unsigned hexadecimal number.
  15201.                       %%        Literal % character.
  15202.                       
  15203.                    Additional parameters may lie between the % and
  15204.                    the control letter:
  15205.  
  15206.                       -         Left-justify expression in its field.
  15207.                       width     Pad field to this width as needed;
  15208.                                 leading 0 pads with zeros.
  15209.                       .prec     Maximum string width or digits to
  15210.                                 right of decimal point.
  15211.  
  15212.  
  15213.  
  15214.  
  15215.  
  15216.  
  15217.  
  15218.  
  15219.  
  15220.  
  15221.  
  15222.  
  15223.  
  15224.  
  15225.  
  15226.  
  15227.  
  15228.  
  15229.  
  15230.  
  15231.  
  15232.  
  15233.  
  15234.  
  15235.  
  15236.  
  15237.  
  15238.                                      Page 239
  15239.  
  15240.      Built-in Procedures
  15241.  
  15242.  
  15243.             
  15244.  
  15245.  
  15246.  
  15247.  
  15248.  
  15249.  
  15250.  
  15251.  
  15252.  
  15253.  
  15254.  
  15255.  
  15256.  
  15257.  
  15258.  
  15259.  
  15260.  
  15261.  
  15262.  
  15263.  
  15264.  
  15265.  
  15266.  
  15267.  
  15268.  
  15269.  
  15270.  
  15271.  
  15272.  
  15273.  
  15274.  
  15275.  
  15276.  
  15277.  
  15278.  
  15279.  
  15280.  
  15281.  
  15282.  
  15283.  
  15284.  
  15285.  
  15286.  
  15287.  
  15288.  
  15289.  
  15290.  
  15291.  
  15292.  
  15293.  
  15294.  
  15295.  
  15296.  
  15297.  
  15298.  
  15299.  
  15300.                                      Page 240
  15301.  
  15302.                                                                     Utilities
  15303.  
  15304.  
  15305.             
  15306.  
  15307.  
  15308.                                Built-in Utilities
  15309.  
  15310.  
  15311.                    Command                Function               
  15312.  
  15313.                    cd                     Change working directory.
  15314.                                           Optionally, change disk.
  15315.  
  15316.                    chcp                   Change code page.  (Not
  15317.                                           implemented on NT.)
  15318.  
  15319.                    chdir                  A synonym for cd.
  15320.  
  15321.                    cls                    Clear the screen.
  15322.  
  15323.                    dirs                   Print the directory stack.
  15324.  
  15325.                    echo                   Echo arguments to stdout.
  15326.  
  15327.                    eval                   Defer parsing of the word
  15328.                                           list until the evaluation
  15329.                                           phase.
  15330.  
  15331.                    hashstat               Print path hash statistics.
  15332.  
  15333.                    heapstat               Print heap usage
  15334.                                           statistics.
  15335.  
  15336.                    history                Display the history list.
  15337.  
  15338.                    kill                   Kill background activity.
  15339.  
  15340.                    popd                   Pop directory stack.
  15341.  
  15342.                    ps                     List process and thread
  15343.                                           status.
  15344.  
  15345.                    pushd                  Push a new current
  15346.                                           directory on the directory
  15347.                                           stack or exchange the top
  15348.                                           two items.
  15349.  
  15350.                    rehash                 Rehash the path
  15351.                                           directories.
  15352.  
  15353.                    rotd                   Rotate the directory stack.
  15354.  
  15355.                    sleep                  Sleep for a specified
  15356.                                           period.
  15357.  
  15358.                    source                 Read commands from a file.
  15359.  
  15360.  
  15361.  
  15362.                                      Page 241
  15363.  
  15364.      Utilities
  15365.  
  15366.  
  15367.                    unhash                 Turn off path list hashing.
  15368.  
  15369.                    verify                 Turn on write verification
  15370.                                           mode.
  15371.  
  15372.                    wait                   Wait for children to
  15373.                                           complete.
  15374.  
  15375.  
  15376.                    All built-in utilities self-document with the -h
  15377.                    option.
  15378.  
  15379.  
  15380.  
  15381.  
  15382.  
  15383.  
  15384.  
  15385.  
  15386.  
  15387.  
  15388.  
  15389.  
  15390.  
  15391.  
  15392.  
  15393.  
  15394.  
  15395.  
  15396.  
  15397.  
  15398.  
  15399.  
  15400.  
  15401.  
  15402.  
  15403.  
  15404.  
  15405.  
  15406.  
  15407.  
  15408.  
  15409.  
  15410.  
  15411.  
  15412.  
  15413.  
  15414.  
  15415.  
  15416.  
  15417.  
  15418.  
  15419.  
  15420.  
  15421.  
  15422.  
  15423.  
  15424.                                      Page 242
  15425.  
  15426.                                                                     Utilities
  15427.  
  15428.  
  15429.             
  15430.  
  15431.  
  15432.                                External Utilities
  15433.  
  15434.  
  15435.                    Command                Function               
  15436.  
  15437.                    binedit                Binary edit.
  15438.  
  15439.                    cat                    Concatenate files.
  15440.  
  15441.                    chmod                  Change mode bits of file.
  15442.  
  15443.                    cp                     Copy files or directories.
  15444.  
  15445.                    cron                   Run commands at specified
  15446.                                           times.
  15447.  
  15448.                    cut                    Cut out selected fields of
  15449.                                           each line of text.
  15450.  
  15451.                    des                    Encrypt or decrypt data
  15452.                                           using the Data Encryption
  15453.                                           Standard (DES).  Due to
  15454.                                           U.S. Federal Law, this
  15455.                                           utility cannot be exported
  15456.                                           outside the U.S. or Canada.
  15457.  
  15458.                    date                   Display the date and time.
  15459.  
  15460.                    diff                   Compare files or
  15461.                                           directories.
  15462.  
  15463.                    dim                    Discard any ansi escape
  15464.                                           sequences in the input
  15465.                                           stream.
  15466.  
  15467.                    dskread                Read raw sectors from a
  15468.                                           disk.
  15469.  
  15470.                    dskwrite               Write raw sectors to a
  15471.                                           disk.
  15472.  
  15473.                    du                     Display disk usage.
  15474.  
  15475.                    fgrep                  Fast string search (fast
  15476.                                           grep) of text files.
  15477.  
  15478.                    grep                   Regular expression pattern
  15479.                                           search of text files.
  15480.  
  15481.                    head                   Copy the first few lines or
  15482.                                           bytes of a file to stdout.
  15483.  
  15484.  
  15485.  
  15486.                                      Page 243
  15487.  
  15488.      Utilities
  15489.  
  15490.  
  15491.                    label                  Read/Write the volume
  15492.                                           label.
  15493.  
  15494.                    ls                     List directory contents.
  15495.  
  15496.                    markexe                Mark an .exe file to
  15497.                                           indicate what sort of
  15498.                                           application it is.  (OS/2
  15499.                                           only.)
  15500.  
  15501.                    mkdir                  Make a new directory.
  15502.  
  15503.                    more                   A better more utility.
  15504.                                           (Able to search forward or
  15505.                                           backward or to a specific
  15506.                                           line.)
  15507.  
  15508.  
  15509.  
  15510.  
  15511.  
  15512.  
  15513.  
  15514.  
  15515.  
  15516.  
  15517.  
  15518.  
  15519.  
  15520.  
  15521.  
  15522.  
  15523.  
  15524.  
  15525.  
  15526.  
  15527.  
  15528.  
  15529.  
  15530.  
  15531.  
  15532.  
  15533.  
  15534.  
  15535.  
  15536.  
  15537.  
  15538.  
  15539.  
  15540.  
  15541.  
  15542.  
  15543.  
  15544.  
  15545.  
  15546.  
  15547.  
  15548.                                      Page 244
  15549.  
  15550.                                                                     Utilities
  15551.  
  15552.  
  15553.             
  15554.  
  15555.  
  15556.                                External Utilities
  15557.  
  15558.  
  15559.                    Command                Function               
  15560.  
  15561.                    moreh                  A large model version of
  15562.                                           more.
  15563.  
  15564.                    mt                     Manipulate the tape device.
  15565.                                           (NT only.)
  15566.  
  15567.                    mv                     Move files or directories.
  15568.  
  15569.                    newer                  Test whether first file is
  15570.                                           newer than the others.
  15571.  
  15572.                    older                  Test whether first file is
  15573.                                           older than the others.
  15574.  
  15575.                    patchlnk               A (very) special-purpose
  15576.                                           utility to patch a bug in
  15577.                                           the Microsoft linker on
  15578.                                           OS/2.
  15579.  
  15580.                    pwd                    Print the working
  15581.                                           directories.
  15582.  
  15583.                    rm                     Remove files or
  15584.                                           directories.
  15585.  
  15586.                    rmdir                  Remove directories.
  15587.  
  15588.                    sed                    Stream editor.
  15589.  
  15590.                    setrows                Set or report the number of
  15591.                                           rows in the display window.
  15592.                                           (OS/2 only.)
  15593.  
  15594.                    split                  Split a large file into
  15595.                                           equal-sized chunks.
  15596.  
  15597.                    startwin               Start Win3.x applications
  15598.                                           under OS/2 2.x.
  15599.  
  15600.                    strings                Extract ASCII strings from
  15601.                                           a file.
  15602.  
  15603.                    sum                    Checksum the contents of a
  15604.                                           file.
  15605.  
  15606.                    tabs                   Expand/Unexpand tabs.
  15607.  
  15608.  
  15609.  
  15610.                                      Page 245
  15611.  
  15612.      Utilities
  15613.  
  15614.  
  15615.                    tail                   Copy the last few lines or
  15616.                                           bytes of a file to stdout.
  15617.  
  15618.                    tar                    Read/Write UNIX TAR and
  15619.                                           CPIO format files.
  15620.  
  15621.                    tee                    Pipe fitting.
  15622.  
  15623.                    touch                  Update the time-stamp on a
  15624.                                           file.
  15625.  
  15626.                    tr                     Translate characters.
  15627.  
  15628.                    uniq                   Report unique lines in text
  15629.                                           files.
  15630.  
  15631.  
  15632.  
  15633.  
  15634.  
  15635.  
  15636.  
  15637.  
  15638.  
  15639.  
  15640.  
  15641.  
  15642.  
  15643.  
  15644.  
  15645.  
  15646.  
  15647.  
  15648.  
  15649.  
  15650.  
  15651.  
  15652.  
  15653.  
  15654.  
  15655.  
  15656.  
  15657.  
  15658.  
  15659.  
  15660.  
  15661.  
  15662.  
  15663.  
  15664.  
  15665.  
  15666.  
  15667.  
  15668.  
  15669.  
  15670.  
  15671.  
  15672.                                      Page 246
  15673.  
  15674.                                                                     Utilities
  15675.  
  15676.  
  15677.             
  15678.  
  15679.  
  15680.                                External Utilities
  15681.  
  15682.  
  15683.                    Command                Function               
  15684.  
  15685.                    ver                    Display the current system
  15686.                                           and Hamilton C shell
  15687.                                           version numbers.
  15688.  
  15689.                    vol                    Display the disk volume
  15690.                                           label.
  15691.  
  15692.                    wc                     Count lines, words and
  15693.                                           characters.
  15694.  
  15695.                    whereis                Tell which PATH directory a
  15696.                                           given executable is in.
  15697.  
  15698.                    xd                     Hex dump a file to stdout.
  15699.  
  15700.  
  15701.                    All external utilities except whereis self-
  15702.                    document with the -h option.  Any external utility
  15703.                    may be renamed simply by renaming the executable
  15704.                    file.
  15705.  
  15706.  
  15707.  
  15708.                                         
  15709.  
  15710.  
  15711.  
  15712.  
  15713.  
  15714.  
  15715.  
  15716.  
  15717.  
  15718.  
  15719.  
  15720.  
  15721.  
  15722.  
  15723.  
  15724.  
  15725.  
  15726.  
  15727.  
  15728.  
  15729.  
  15730.  
  15731.  
  15732.  
  15733.  
  15734.                                      Page 247
  15735.  
  15736.      Popular Aliases
  15737.  
  15738.  
  15739.             
  15740.  
  15741.  
  15742.                                  Popular Aliases
  15743.  
  15744.  
  15745.                    Command   Definition   Function               
  15746.  
  15747.                    app       cat >>       Append to a file.
  15748.  
  15749.                    beep      eval echo -n ^a   Beep sound.
  15750.  
  15751.                    breaksw   break        Older BSD4.3 name for a
  15752.                                           break statement inside a
  15753.                                           switch.
  15754.  
  15755.                    cdd       cd +c        Change the directory and
  15756.                                           disk in one command.
  15757.  
  15758.                    copy      local s ; @ s = $nowild ; @ nowild = 1 ;
  15759.                                           safecopy
  15760.                                           Invoke the standard IBM/MS
  15761.                                           copy command with shell
  15762.                                           wildcarding turned off so
  15763.                                           copy will work sensibly.
  15764.  
  15765.                    date      dt           Display the current time
  15766.                                           and date.
  15767.  
  15768.                    del       local s ; @ s = $nowild ; @ nowild = 1 ;
  15769.                                           safedel
  15770.                                           Invoke the del command with
  15771.                                           shell wildcarding turned
  15772.                                           off so ``del *.*'' will
  15773.                                           still produce the ``Are you
  15774.                                           sure?'' message.
  15775.  
  15776.                    di        diff -b!     Run the diff command,
  15777.                                           ignoring white space
  15778.                                           differences and using color
  15779.                                           to highlight the changes.
  15780.  
  15781.                    dir       cmd /c dir   Invoke the cmd.exe dir
  15782.                                           command.  (Alternately, you
  15783.                                           may wish to intercept dir
  15784.                                           the same way copy or del is
  15785.                                           done, turning off shell
  15786.                                           wildcarding before running
  15787.                                           the command.)
  15788.  
  15789.                    duc       du -c        Disk usage for the current
  15790.                                           disk only.
  15791.  
  15792.  
  15793.  
  15794.  
  15795.  
  15796.                                      Page 248
  15797.  
  15798.                                                               Popular Aliases
  15799.  
  15800.  
  15801.                    dumphist  history -s > ~\history.csh
  15802.                                           Dump out the history list.
  15803.  
  15804.                    endif     end          Older BSD4.3 name for the
  15805.                                           end of an if statement.
  15806.  
  15807.                    endsw     end          Older BSD4.3 name for the
  15808.                                           end of switch statement.
  15809.  
  15810.                    erase     del          Alternate name for del.
  15811.  
  15812.                    f         fgrep        Quicker name for fgrep.
  15813.  
  15814.                    fn        fgrep -n     Fgrep and print line
  15815.                                           numbers.
  15816.  
  15817.  
  15818.  
  15819.  
  15820.  
  15821.  
  15822.  
  15823.  
  15824.  
  15825.  
  15826.  
  15827.  
  15828.  
  15829.  
  15830.  
  15831.  
  15832.  
  15833.  
  15834.  
  15835.  
  15836.  
  15837.  
  15838.  
  15839.  
  15840.  
  15841.  
  15842.  
  15843.  
  15844.  
  15845.  
  15846.  
  15847.  
  15848.  
  15849.  
  15850.  
  15851.  
  15852.  
  15853.  
  15854.  
  15855.  
  15856.  
  15857.  
  15858.                                      Page 249
  15859.  
  15860.      Popular Aliases
  15861.  
  15862.  
  15863.             
  15864.  
  15865.  
  15866.                                  Popular Aliases
  15867.  
  15868.  
  15869.                    Command   Definition   Function               
  15870.  
  15871.                    g         grep         Quicker name for grep.
  15872.  
  15873.                    h         history      Quicker name for history.
  15874.  
  15875.                    help                   Under OS/2, invoke the
  15876.                                           IBM/Microsoft help command.
  15877.                                           Under NT, this is a
  15878.                                           procedure using winerror
  15879.                                           (in the samples directory)
  15880.                                           to print the message
  15881.                                           corresponding to the return
  15882.                                           code from the last command.
  15883.  
  15884.                    home      cdd ~        Change to the home disk and
  15885.                                           directory.
  15886.  
  15887.                    ld        ls -a +D -.  List only the
  15888.                                           subdirectories.
  15889.  
  15890.                    ll        ls -L        List directories, long
  15891.                                           format.
  15892.  
  15893.                    loadhist  source -n ~\history.csh
  15894.                                           Load the history list
  15895.                                           without executing any of
  15896.                                           it.
  15897.  
  15898.                    md        mkdir        Make directories.
  15899.  
  15900.                    mi        moreh -i     Quick interactive startup
  15901.                                           of your favorite version
  15902.                                           more.  Clears the screen
  15903.                                           when it starts up and
  15904.                                           doesn't just exit if
  15905.                                           there's less than a
  15906.                                           screenful.
  15907.  
  15908.                    mih       moreh -i     Huge interactive more.
  15909.  
  15910.                    mis       more -i      Small interactive more.
  15911.  
  15912.                    pause     echo -n Press any key when ready ... ; @
  15913.                                           getchar ; echo
  15914.                                           Pause, waiting for any
  15915.                                           keystroke or character from
  15916.                                           stdin.
  15917.  
  15918.  
  15919.  
  15920.                                      Page 250
  15921.  
  15922.                                                               Popular Aliases
  15923.  
  15924.  
  15925.                    q         exit         Exit the C shell
  15926.  
  15927.                    rd        rmdir        Remove empty directories.
  15928.  
  15929.                    ren       rename       Another name for the rename
  15930.                                           alias.
  15931.  
  15932.                    rename    local s ; @ s = nowild ; @ nowild = 1 ;
  15933.                                           saferename
  15934.                                           Invoke the standard IBM/MS
  15935.                                           rename command with shell
  15936.                                           wildcarding turned off so
  15937.                                           the rename will work
  15938.                                           sensibly.
  15939.  
  15940.  
  15941.  
  15942.  
  15943.  
  15944.  
  15945.  
  15946.  
  15947.  
  15948.  
  15949.  
  15950.  
  15951.  
  15952.  
  15953.  
  15954.  
  15955.  
  15956.  
  15957.  
  15958.  
  15959.  
  15960.  
  15961.  
  15962.  
  15963.  
  15964.  
  15965.  
  15966.  
  15967.  
  15968.  
  15969.  
  15970.  
  15971.  
  15972.  
  15973.  
  15974.  
  15975.  
  15976.  
  15977.  
  15978.  
  15979.  
  15980.  
  15981.  
  15982.                                      Page 251
  15983.  
  15984.      Popular Aliases
  15985.  
  15986.  
  15987.             
  15988.  
  15989.  
  15990.                                  Popular Aliases
  15991.  
  15992.  
  15993.                    Command   Definition   Function               
  15994.  
  15995.                    start     cmd /c start Start a new session via the
  15996.                                           cmd.exe start command.
  15997.  
  15998.                    type      cat          Copy files to stdout.
  15999.  
  16000.                    vol       vl           List volume labels.
  16001.  
  16002.                    w         (wait; beep) Wait for background
  16003.                                           processes and beep.
  16004.  
  16005.                    xcopy     local s ; @ s = nowild ; @ nowild = 1 ;
  16006.                                           safexcopy
  16007.                                           Invoke the standard IBM/MS
  16008.                                           xcopy command with shell
  16009.                                           wildcarding turned off so
  16010.                                           xcopy will work sensibly.
  16011.  
  16012.  
  16013.  
  16014.  
  16015.  
  16016.  
  16017.  
  16018.  
  16019.  
  16020.  
  16021.  
  16022.  
  16023.  
  16024.  
  16025.  
  16026.  
  16027.  
  16028.  
  16029.  
  16030.  
  16031.  
  16032.  
  16033.  
  16034.  
  16035.  
  16036.  
  16037.  
  16038.  
  16039.  
  16040.  
  16041.  
  16042.  
  16043.  
  16044.                                      Page 252
  16045.  
  16046.                                                               Popular Aliases
  16047.  
  16048.  
  16049.             
  16050.  
  16051.  
  16052.  
  16053.  
  16054.  
  16055.  
  16056.  
  16057.  
  16058.  
  16059.  
  16060.  
  16061.  
  16062.  
  16063.  
  16064.  
  16065.  
  16066.  
  16067.  
  16068.  
  16069.  
  16070.  
  16071.  
  16072.  
  16073.  
  16074.  
  16075.  
  16076.  
  16077.  
  16078.  
  16079.  
  16080.  
  16081.  
  16082.  
  16083.  
  16084.  
  16085.  
  16086.  
  16087.  
  16088.  
  16089.  
  16090.  
  16091.  
  16092.  
  16093.  
  16094.  
  16095.  
  16096.  
  16097.  
  16098.  
  16099.  
  16100.  
  16101.  
  16102.  
  16103.  
  16104.  
  16105.  
  16106.                                      Page 253
  16107.  
  16108.      Help
  16109.  
  16110.  
  16111.  
  16112.                             Help for Hamilton C shell
  16113.  
  16114.  
  16115.             csh:      Startup the Hamilton C shell
  16116.  
  16117.                  Usage:  csh [-!BbefFhHiKLlNnsTtuXYZ-] [-IO] [+IO] [-
  16118.                  cC command]
  16119.                            [arguments ... ]
  16120.  
  16121.                  Options:
  16122.  
  16123.                      -!  Ignore errors:  Continue execution even if a
  16124.                          command terminates abnormally.  (Implied by
  16125.                          interactive.)
  16126.                      -B  Berkeley mode for better compatibility with
  16127.                          the BSD4.3 C shell for commands typed, not
  16128.                          just those read from a script starting with
  16129.                          #!/bin/csh.
  16130.                      -b  No Berkeley compatibility mode at all, not
  16131.                          even on scripts starting with #!/bin/csh.
  16132.                      -c  Execute the command following on the command
  16133.                          line, then exit.  (Implies not interactive.)
  16134.                      -C  Normally, this means immediately run the
  16135.                          command on the command line, then continue
  16136.                          with normal startup and processing of stdin.
  16137.                          But for compatibility with cmd.exe, the -X
  16138.                          option may be used to toggle this to have
  16139.                          the same meaning as -c but with the initial
  16140.                          greeting and copyright notice suppressed.
  16141.                      -e  Echo the raw input to stdout.
  16142.                      -f  Fast startup:  Don't look for a startup.csh
  16143.                          file.
  16144.                      -F  Faster startup:  Don't look for a
  16145.                          startup.csh file and don't hash the path
  16146.                          directories.
  16147.                      -H  Heapstats.  At some penalty in performance,
  16148.                          this causes the shell to keep a count of the
  16149.                          number and total size of all objects
  16150.                          allocated or freed from the heap.
  16151.                          Statistics can be displayed using the
  16152.                          heapstat command.
  16153.                      -i  Interactive (even if stdin appears to be a
  16154.                          file or a pipe):  Prompt for input and show
  16155.                          the result of history substitutions.
  16156.                      -I  Start with command-line editing in insert
  16157.                          mode.
  16158.                      +I  Start every command in insert mode.
  16159.                      -K  Do a fast startup, skipping both the
  16160.                          login.csh and startup.csh files, run the
  16161.                          command on the command line, and exit.
  16162.                      -L  Login shell:  Look for login.csh and
  16163.                          logout.csh and do history save at exit if
  16164.                          savehist == 1.
  16165.  
  16166.  
  16167.  
  16168.                                      Page 254
  16169.  
  16170.                                                                          Help
  16171.  
  16172.  
  16173.                      -l  same as -L.
  16174.                      -N  No space after the last filename generated
  16175.                          by filename completion.  (It's convenient to
  16176.                          set this with CSHOPTIONS.)
  16177.                      -n  No execution:  Parse commands looking for
  16178.                          syntax errors but don't execute them.
  16179.                      -O  Start with command-line editing in
  16180.                          overstrike (default) mode.
  16181.                      +O  Start every command in overstrike mode.
  16182.                      -s  Read and execute a single line from stdin.
  16183.                          (Implies not interactive.)
  16184.                      -T  Plain Tab key.   Tab and BackTab are
  16185.                          normally used to do filename completion and
  16186.                          to walk file-by-file through the list of
  16187.                          filenames that were matched.  To type an
  16188.                          ordinary Tab character, Ctrl-Tab is used.
  16189.                          This option reverses Tab and Ctrl-Tab,
  16190.                          making Tab a plain character and Ctrl-Tab
  16191.                          the filename completion key.
  16192.                      -t  Suppress callstack tracing.  Error messages
  16193.                          will not include a dump of the callstack but
  16194.                          performance will be improved slightly.
  16195.                      -u  Reads from devices or pipes should be
  16196.                          unbuffered.  (Intended to all the shell to
  16197.                          be used over a comm line.)
  16198.                      -X  Toggle between the normal meaning of -C and
  16199.                          a cmd.exe-compatible interpretation.  You
  16200.                          can set this with the CSHOPTIONS
  16201.                          environmental variable in combination with
  16202.                          setting COMSPEC to point to the C shell to
  16203.                          allow programs that use /C to pass commands
  16204.                          to cmd.exe to be used with the C shell
  16205.                          instead.
  16206.                      -Y  No interrupts.  Don't install an interrupt
  16207.                          handler during startup.  (Ignored under
  16208.                          Windows NT.)
  16209.                      -Z  Very special purpose:  Don't bump the
  16210.                          maximum file handle count during shell
  16211.                          initialization.  Use this option under OS/2
  16212.                          as a workaround if you encounter an
  16213.                          application that fails if it inherits a
  16214.                          larger limit.  This option only works from
  16215.                          the Start Programs or Group menus, not the
  16216.                          command line.  Under NT, this option affects
  16217.                          only the limit on the number of open file
  16218.                          handles on a FAT filesystem; it has no
  16219.                          effect on HPFS or NTFS files.
  16220.                      -h  Help.
  16221.                      --  End of options.
  16222.  
  16223.  
  16224.             (If preferred,  the slash, ``/,'' may be used in place of
  16225.             a minus to introduce options.)
  16226.  
  16227.  
  16228.  
  16229.  
  16230.                                      Page 255
  16231.  
  16232.      Help
  16233.  
  16234.  
  16235.  
  16236.                              Help for the Utilities
  16237.  
  16238.  
  16239.             binedit:  Binary Edit
  16240.  
  16241.                  Usage:  binedit [-ih!-] [-r replace] search file1 [
  16242.                  file2 ... ]
  16243.  
  16244.                     binedit is  a very  simple utility  for  scanning
  16245.                     arbitrary  files,   looking  for  and  optionally
  16246.                     changing any references to the search argument to
  16247.                     the replacement  value.   binedit is quite useful
  16248.                     patching  binary  files,  e.g.,  to  replace  all
  16249.                     occurrences of C:\OS2 with C:\1.X.
  16250.  
  16251.                     Occurrences will  be reported as hex offsets from
  16252.                     the start  of the  files you  name.   You can use
  16253.                     these numbers  to go examine the file with IBM/MS
  16254.                     patch.exe  if   you  like  and  make  the  change
  16255.                     manually.
  16256.  
  16257.                     You can  also ask  binedit to  make  the  change,
  16258.                     using the  -r (replace)  option.   Nothing fancy.
  16259.                     It just changes all occurrences to the string you
  16260.                     specify and quits.
  16261.  
  16262.                     Neither the  search nor  the replace  string  may
  16263.                     contain null  characters, but otherwise there are
  16264.                     no restrictions.
  16265.  
  16266.                  Options:
  16267.  
  16268.                      -h  Help.  (This screen.)
  16269.                      -i  Ignore character case in the search
  16270.                          argument.
  16271.                      -r replace Replace any occurrences of the search
  16272.                                 string with this replacement value.
  16273.                      -!  Pad with nulls or truncate the replace
  16274.                          string to be the same length as the search
  16275.                          string.  (Otherwise, it's an error if
  16276.                          they're different lengths.)
  16277.                      --  End of options.
  16278.  
  16279.  
  16280.             cat:      Concatenate Files to Stdout
  16281.  
  16282.                  Usage:  cat [-h-] [ file1 file2 ... ]
  16283.  
  16284.                     cat copies the files you specify, one immediately
  16285.                     after another,  onto stdout.   No  end-of-file or
  16286.                     other delimiter  characters are  inserted between
  16287.                     files.
  16288.  
  16289.  
  16290.  
  16291.  
  16292.                                      Page 256
  16293.  
  16294.                                                                          Help
  16295.  
  16296.  
  16297.                  Options:
  16298.  
  16299.                      -h  Help.
  16300.                      --  End of options.
  16301.  
  16302.  
  16303.             cd:       Change to a New Current Directory
  16304.  
  16305.                  Usage:  cd [-chr-] [+chr] [ directory ]
  16306.  
  16307.                     cd works  exactly like  the  one  in  cmd.exe  by
  16308.                     default:  if you specify a directory, it tries to
  16309.                     make that  the current  on appropriate  disk  but
  16310.                     won't change  your current  disk.   If you  don't
  16311.                     specify  a  directory,  it  reports  the  current
  16312.                     setting.
  16313.  
  16314.                     If the  path you  specify is just 3 or more dots,
  16315.                     cd will interpret that specially.  Just as ``..''
  16316.                     means go up one level, ``...'' means up 2 levels,
  16317.                     ``....'' means  up 3  levels,  etc.    Note  that
  16318.                     ``...'' is  also a  wildcard notation for zero or
  16319.                     more directory  levels, but only if it's preceded
  16320.                     by ``\'',  ``/'', ``~''  or ``:''  or followed by
  16321.                     ``\'' or  ``/'', so  usually there's  no conflict
  16322.                     with  this   notation  for   going  up   multiple
  16323.                     directories with cd.  The exception is when you'd
  16324.                     like  to   go  up   multiple  directories  on  an
  16325.                     explicitly specified  drive; in that case, you'll
  16326.                     have  to   quote  the   word  to   turn  off  the
  16327.                     wildcarding.
  16328.  
  16329.                     This version  of cd also supports CDPATH.  If you
  16330.                     specify a  path that  isn't found,  cd will  look
  16331.                     through the  list of  any directories you specify
  16332.                     in the  CDPATH  environmental  variable  (or  the
  16333.                     equivalent cdpath  shell variable)  to see if the
  16334.                     directory  you   want  is   in   one   of   those
  16335.                     directories.  The syntax for CDPATH and cdpath is
  16336.                     the same  as for  PATH or  path except  that  the
  16337.                     current directory need not be listed.
  16338.  
  16339.                     (See  also   the  dirs,   pushd,  popd  and  rotd
  16340.                     commands.)
  16341.  
  16342.                  Options:
  16343.  
  16344.                     If you  set the  chgdisk variable equal to 1 (its
  16345.                     default  is  0),  cd  will  automatically  change
  16346.                     current disks  if the  directory  is  on  another
  16347.                     drive.  The  +c  and  -c  options  allow  you  to
  16348.                     manually control this drive switching:
  16349.  
  16350.                      +c  Automatically change the current disk.
  16351.  
  16352.  
  16353.  
  16354.                                      Page 257
  16355.  
  16356.      Help
  16357.  
  16358.  
  16359.                      -c  Don't automatically change current disk.
  16360.  
  16361.                     If you  set the cdhome variable to 1 (its default
  16362.                     is 0),  cd will  change to your home directory if
  16363.                     you specify one instead of reporting your current
  16364.                     position.  You can manually control this with the
  16365.                     +r and -r options:
  16366.  
  16367.                      +r  Report but don't change the current
  16368.                          directory if no destination directory is
  16369.                          specified.
  16370.                      -r  Change to the home directory in this
  16371.                          situation.
  16372.  
  16373.  
  16374.  
  16375.  
  16376.  
  16377.  
  16378.  
  16379.  
  16380.  
  16381.  
  16382.  
  16383.  
  16384.  
  16385.  
  16386.  
  16387.  
  16388.  
  16389.  
  16390.  
  16391.  
  16392.  
  16393.  
  16394.  
  16395.  
  16396.  
  16397.  
  16398.  
  16399.  
  16400.  
  16401.  
  16402.  
  16403.  
  16404.  
  16405.  
  16406.  
  16407.  
  16408.  
  16409.  
  16410.  
  16411.  
  16412.  
  16413.  
  16414.  
  16415.  
  16416.                                      Page 258
  16417.  
  16418.                                                                          Help
  16419.  
  16420.  
  16421.                      -h  Help.
  16422.                      --  End of options.
  16423.  
  16424.  
  16425.             chcp:     Report or Change the Code Page
  16426.  
  16427.                  Usage:  chcp [-h-] [ page ]
  16428.  
  16429.                     Change to  the specified  OS/2 character set code
  16430.                     page.   If  no  page  is  specified,  report  the
  16431.                     current active and prepared pages.  (This command
  16432.                     is not yet supported under NT.)
  16433.  
  16434.                  Options:
  16435.  
  16436.                      -h  Help.
  16437.                      --  End of options.
  16438.  
  16439.  
  16440.             chmod:    Change Mode Bits on Files or Directories
  16441.  
  16442.                  Usage:  chmod [-+] [rRAHSh] pathname1 [ pathname2
  16443.                  ... ]
  16444.  
  16445.                  Options:
  16446.  
  16447.                      -r  Recursively change contents of directories.
  16448.                      +R  Read-only mode is set.  (The file is write-
  16449.                          protected.)
  16450.                      -R  Read-only mode is turned off.
  16451.                      +A  Archive bit is set.
  16452.                      -A  Archive bit is turned off.
  16453.                      +H  Hidden mode is set.
  16454.                      -H  Hidden mode is turned off.
  16455.                      +S  Mark as a System file.
  16456.                      -S  Mark as a normal user file.
  16457.                      -h  Help.
  16458.                      --  End of options.
  16459.  
  16460.  
  16461.             cls:      Clear the Screen
  16462.  
  16463.                  Usage:  cls [-h-]
  16464.  
  16465.                  Options:
  16466.  
  16467.                      -h  Help.
  16468.                      --  End of options.
  16469.  
  16470.  
  16471.  
  16472.  
  16473.  
  16474.  
  16475.  
  16476.  
  16477.  
  16478.                                      Page 259
  16479.  
  16480.      Help
  16481.  
  16482.  
  16483.             cp:       Copy Files or Directories
  16484.  
  16485.                  Usage:  cp [-filmh-] source1 [ source2 ... ]
  16486.                  destination
  16487.  
  16488.                     cp can  copy both  files and directories.  If the
  16489.                     destination is  an existing directory, the source
  16490.                     object(s) will be copied into that directory.  If
  16491.                     more than  one source  object is  specified,  the
  16492.                     destination must  be a directory, but it need not
  16493.                     already exist.
  16494.  
  16495.                     If a  destination file already exists, it will be
  16496.                     overwritten; this  is not considered an error and
  16497.                     no diagnostic message is given.
  16498.  
  16499.                  Options:
  16500.  
  16501.                      -f  Force read-only files to be overwritten.
  16502.                      -i  Interactive:  ask before copying each object
  16503.                          on the command line.
  16504.                      -l  Logging is on:  display the name of each
  16505.                          file or directory as it's copied.
  16506.                      -m  Merge sub-directories of same name in source
  16507.                          and destination.
  16508.                      -h  Help.
  16509.                      --  End of options.  (Useful if filenames start
  16510.                          with ``-''.)
  16511.  
  16512.  
  16513.  
  16514.  
  16515.  
  16516.  
  16517.  
  16518.  
  16519.  
  16520.  
  16521.  
  16522.  
  16523.  
  16524.  
  16525.  
  16526.  
  16527.  
  16528.  
  16529.  
  16530.  
  16531.  
  16532.  
  16533.  
  16534.  
  16535.  
  16536.  
  16537.  
  16538.  
  16539.  
  16540.                                      Page 260
  16541.  
  16542.                                                                          Help
  16543.  
  16544.  
  16545.             cron:     Run Commands at Specified Times
  16546.  
  16547.                  Usage:  cron [-asLwh-] [-o<opt>] [-d <dir>] [
  16548.                  crontab1 crontab2 ... ]
  16549.  
  16550.                     cron executes  commands at times according to the
  16551.                     crontab (.crt)  files  specifed.    If  any  path
  16552.                     specified is  a  directory,  cron  will  run  any
  16553.                     crontab  files   in   that   directory   or   any
  16554.                     subdirectory.   If no  files are  specified, cron
  16555.                     will read the crontab from stdin.
  16556.  
  16557.                     Each file  is  expected  to  contain  a  list  of
  16558.                     activities to  be run at certain times, specified
  16559.                     one per  line.   There are  six fields  per line,
  16560.                     separated  by   white  space.    The  first  five
  16561.                     specify:
  16562.  
  16563.                        minute         (0-59)
  16564.                        hour           (0-23)
  16565.                        day of the month   (1-31)
  16566.                        month of the year  (1-12)
  16567.                        day of the week    (0-6, 0 is Sunday)
  16568.  
  16569.                     Each of  these fields may be an asterisk (meaning
  16570.                     all legal  values) or  a comma-separated  list of
  16571.                     elements, where  each element  is either a single
  16572.                     number or a range, given as two numbers separated
  16573.                     by a minus.  If either end of a range is omitted,
  16574.                     it defaults to the highest/lowest legal value, as
  16575.                     appropriate.   If the  days are specified in both
  16576.                     day of  the month and day of the week fields, the
  16577.                     union of  those fields  is used;  to specify  the
  16578.                     days by  only one  field, the  other should be an
  16579.                     asterisk.   For example,  0 0 1 * 1 means run the
  16580.                     command at  midnight on  the first of every month
  16581.                     and also on every Monday.
  16582.  
  16583.                     The sixth field of each line is a command that is
  16584.                     to be  executed by  the shell  at  the  specified
  16585.                     times.   Any percent  characters  in  this  field
  16586.                     (unless escaped  by  the  escape  character)  are
  16587.                     translated     to     carriage     return/newline
  16588.                     combinations.   Only the  first line  (up to  the
  16589.                     first %  or end  of line) is passed as a command;
  16590.                     the other  lines are  written  to  the  shell  as
  16591.                     stdin.   If no  input lines  are given, the shell
  16592.                     will inherit stdin opened to the nul device.
  16593.  
  16594.                     If the  crontab was  read from  a file, the shell
  16595.                     will  inherit   stdout  and  stderr  handles  for
  16596.                     writing (appending,  if the  file already exists)
  16597.                     to a file created by replacing the .crt extension
  16598.                     on the  crontab file  with .nnn, where nnn is the
  16599.  
  16600.  
  16601.  
  16602.                                      Page 261
  16603.  
  16604.      Help
  16605.  
  16606.  
  16607.                     linenumber in the .crt file.  (If the crontab was
  16608.                     read from  stdin, then the shell will inherit the
  16609.                     stdout and  stderr that  cron inherited  when  it
  16610.                     started.)
  16611.  
  16612.                     If a  syntax or  other error  is encountered in a
  16613.                     crontab, that  line, but not the rest of the file
  16614.                     will be  ignored.   The rationale  is  that  cron
  16615.                     should continue  running even  if  it  encounters
  16616.                     problems; it  should not  be necessary to restart
  16617.                     it  just   because  one   entry  in  one  crontab
  16618.                     contained an error.
  16619.  
  16620.                     By default,  if the  crontab is read from a file,
  16621.                     commands will be run asynchronously, meaning that
  16622.                     all entries  that are  ready to  run at any given
  16623.                     time will  be quickly  spawned, one  right  after
  16624.                     another, without  waiting for  each  to  complete
  16625.                     before the  next is  spawned.   If the crontab is
  16626.                     read from  stdin, the default will be synchronous
  16627.                     execution, meaning  each must complete before the
  16628.                     next starts;  that's so any output from one won't
  16629.                     be jumbled  with that of another.  These defaults
  16630.                     can be overridden with command-line options.
  16631.  
  16632.                     Once it's started, cron will make an initial scan
  16633.                     of the  crontab files or directories.  Once every
  16634.                     minute after that it will look for any changes by
  16635.                     comparing timestamps on the files.
  16636.  
  16637.                  Options:
  16638.  
  16639.                      -a  Asynchronout execution.  Don't wait for one
  16640.                          command to complete before spawning the
  16641.                          next, even if the crontab was read from
  16642.                          stdin.
  16643.                      -s  Synchronous execution.   Always wait for one
  16644.                          command to complete before spawing the next,
  16645.                          even if the crontab was read from a file.
  16646.                      -L  Logging.  As each command is spawned,
  16647.                          timestamp and log it to stdout and to the
  16648.                          output file if that's not the same as
  16649.                          stdout.
  16650.                      -w  Wait 'till whole minute.  If cron wasn't
  16651.                          started near a whole minute (i.e., zero to
  16652.                          three seconds past a whole minute mark),
  16653.                          wait 'till the next whole minute before
  16654.                          beginning to schedule cron events.
  16655.                      -o<opt>    Remainder of word contains options to
  16656.                          be passed to the C shell with any commands.
  16657.                          E.g., -oF means C shell should do fast
  16658.                          startup when running commands.
  16659.  
  16660.  
  16661.  
  16662.  
  16663.  
  16664.                                      Page 262
  16665.  
  16666.                                                                          Help
  16667.  
  16668.  
  16669.                      -d <dir>   Output files should be created in the
  16670.                          specified directory, not the directory where
  16671.                          the .crt files were found.
  16672.                      -h  Help.  (This screen.)
  16673.                      --  End of options.
  16674.  
  16675.  
  16676.  
  16677.  
  16678.  
  16679.  
  16680.  
  16681.  
  16682.  
  16683.  
  16684.  
  16685.  
  16686.  
  16687.  
  16688.  
  16689.  
  16690.  
  16691.  
  16692.  
  16693.  
  16694.  
  16695.  
  16696.  
  16697.  
  16698.  
  16699.  
  16700.  
  16701.  
  16702.  
  16703.  
  16704.  
  16705.  
  16706.  
  16707.  
  16708.  
  16709.  
  16710.  
  16711.  
  16712.  
  16713.  
  16714.  
  16715.  
  16716.  
  16717.  
  16718.  
  16719.  
  16720.  
  16721.  
  16722.  
  16723.  
  16724.  
  16725.  
  16726.                                      Page 263
  16727.  
  16728.      Help
  16729.  
  16730.  
  16731.             cut:      Cut out selected fields of each line of text,
  16732.  
  16733.                  Usage:  cut [-hsr-] [-c<list>] [-f<list>] [-
  16734.                  d<delims>] [ file1 file2 ...]
  16735.  
  16736.                     cut can  be used  to select  certain  columns  or
  16737.                     fields from each line of input.  If the -c option
  16738.                     is used, fields are defined as specific character
  16739.                     positions.   If the -f option is used, the fields
  16740.                     can be  of variable  length, each field separated
  16741.                     from the  next by the delimiter character.  If no
  16742.                     files are  specified, cut  reads input  data from
  16743.                     stdin.
  16744.  
  16745.                     A  list  of  fields  or  character  positions  is
  16746.                     specified as  a comma-separated list of integers.
  16747.                     The minus  sign can  be used to indicate a range.
  16748.                     Here are  some examples:    1,4,7;  1-3,8;  -5,10
  16749.                     (short  for  1-5,10);  or  3-  (short  for  third
  16750.                     through last field.)
  16751.  
  16752.                  Options:
  16753.  
  16754.                      -h  Help.  (This screen.)
  16755.                      -s  Suppress lines with no delimiters in case of
  16756.                          -f option.  Otherwise, lines with no
  16757.                          delimiters are passed through unchanged.
  16758.                      -c<list>   The list specifies character
  16759.                                 positions.
  16760.                      -f<list>   The list specifies field numbers.
  16761.                      -d<delims> The specified characters are used as
  16762.                                 the field delimiters with the -f
  16763.                                 option.  Any number of delimiters can
  16764.                                 be specified.  The default is the tab
  16765.                                 character.
  16766.                      -r  Repeated delimiters are treated as if only a
  16767.                          single delimiter had appeared.
  16768.  
  16769.  
  16770.             date:     Print the Date and Time
  16771.  
  16772.                  Usage:  date [-nh-]
  16773.  
  16774.                     date prints  the day  of the  week, the  date and
  16775.                     time of day in 24-hour notation.  This command is
  16776.                     normally stored  in the  file dt.exe  and invoked
  16777.                     with an  alias so  it can  be used  from  cmd.exe
  16778.                     without colliding  with the internal cmd.exe date
  16779.                     function.
  16780.  
  16781.                  Options:
  16782.  
  16783.  
  16784.  
  16785.  
  16786.  
  16787.  
  16788.                                      Page 264
  16789.  
  16790.                                                                          Help
  16791.  
  16792.  
  16793.                      -n  Don't automatically append a Carriage
  16794.                          Return/Line Feed sequence to the end of the
  16795.                          output.
  16796.                      -h  Help.
  16797.                      --  End of options.
  16798.  
  16799.  
  16800.  
  16801.  
  16802.  
  16803.  
  16804.  
  16805.  
  16806.  
  16807.  
  16808.  
  16809.  
  16810.  
  16811.  
  16812.  
  16813.  
  16814.  
  16815.  
  16816.  
  16817.  
  16818.  
  16819.  
  16820.  
  16821.  
  16822.  
  16823.  
  16824.  
  16825.  
  16826.  
  16827.  
  16828.  
  16829.  
  16830.  
  16831.  
  16832.  
  16833.  
  16834.  
  16835.  
  16836.  
  16837.  
  16838.  
  16839.  
  16840.  
  16841.  
  16842.  
  16843.  
  16844.  
  16845.  
  16846.  
  16847.  
  16848.  
  16849.  
  16850.                                      Page 265
  16851.  
  16852.      Help
  16853.  
  16854.  
  16855.             des:      DES Data Encryption
  16856.  
  16857.                  Usage:  des [-edbhnrz-] [-k key] [ file1 file2 ... ]
  16858.  
  16859.                     des is  a filter  that encrypts  or decrypts data
  16860.                     read  from  the  files  you  specify,  one  after
  16861.                     another,  to  stdout  with  the  Data  Encryption
  16862.                     Standard (DES).  If no files are given, des reads
  16863.                     from stdin.  If there are multiple files, they're
  16864.                     simply concatenated as they're read.
  16865.  
  16866.                     Either -e  (encrypt)  or  -d  (decrypt)  must  be
  16867.                     specified. If the key is not given on the command
  16868.                     line with  the -k option, des will prompt for it,
  16869.                     suppressing echo.
  16870.  
  16871.                     Distribution of  this software  is controlled  by
  16872.                     U.S. Federal  Law under Title 22, Code of Federal
  16873.                     Regulations, Subchapter  M, Category XIII(b).  It
  16874.                     may not  be exported  outside the  U.S. or Canada
  16875.                     without an export license.
  16876.  
  16877.                  Options:
  16878.  
  16879.                      -e  Encrypt.
  16880.                      -d  Decrypt.
  16881.                      -b  Electronic Code Book (ECB) mode is used.
  16882.                          The default is to use DES Cipher Block
  16883.                          Chaining (CBC) mode with an initial vector
  16884.                          (IV) of all zeros.  Under ECB mode, each
  16885.                          block of 8 bytes is enciphered
  16886.                          independently, depending only on the key.
  16887.                          Under CBC mode, the enciphering of each
  16888.                          block also depends on the data in the
  16889.                          previous blocks.  The default CBC mode is
  16890.                          considered somewhat more secure.
  16891.                      -k key     Encryption key, typed as a simple
  16892.                                 ascii string.  With an ascii key, DES
  16893.                                 ignores the low order bit of each key
  16894.                                 byte but the high order bit is set
  16895.                                 for odd parity, thus retaining the
  16896.                                 information contained in the low
  16897.                                 order bit.
  16898.                      -x  Hex key.  The key string is a sequence of up
  16899.                          to 16 hex characters, right padded with
  16900.                          zeros.  With a hex key, the low order bit of
  16901.                          each byte is again ignored per the DES
  16902.                          algorithm.  This allows the use of any
  16903.                          arbitrary 56-bit key, including bytes
  16904.                          representing control characters that could
  16905.                          not be typed.
  16906.                      -h  Help.  (This screen.)
  16907.                      
  16908.                  Special Interchange Options:
  16909.  
  16910.  
  16911.  
  16912.                                      Page 266
  16913.  
  16914.                                                                          Help
  16915.  
  16916.  
  16917.                     Not all  DES implementations are the same.  There
  16918.                     are  a   number  of   early  implementations   in
  16919.                     circulation  that  either  poorly  or  improperly
  16920.                     implement DES.   Cipher Block Chaining may not be
  16921.                     supported, forcing the use of the -b option.  You
  16922.                     may also discover other flaws, necessitating that
  16923.                     you  experiment   with  some   of  these  special
  16924.                     options:
  16925.  
  16926.                      -n  Suppress parity calculation on an ascii key.
  16927.                          Just use the low-order 7 bits of each
  16928.                          character as-is.
  16929.                      -r  Convert all \r\n sequences to \n on input
  16930.                          and all \n characters to \r\n sequences on
  16931.                          output.  (Some implementors have used the C
  16932.                          library stdio read and write routines but
  16933.                          have forgotten to use binary mode.)
  16934.                      -z  Do not mark the last block with a length;
  16935.                          just fill it with binary zeros.  If you
  16936.                          encipher, then decipher a file this way, the
  16937.                          result will be padded with zeros out to an
  16938.                          8-byte boundary.
  16939.                      
  16940.                     If you  encounter problems  exchanging  encrypted
  16941.                     data with  another DES implementation, you should
  16942.                     try all  the various  combinations of the -b, -n,
  16943.                     -r and  -z options.   (We've  seen one  very poor
  16944.                     implementation of DES that had all these flaws.)
  16945.  
  16946.                  Notes:
  16947.  
  16948.                      1.  If you lose the key to a file encrypted with
  16949.                          DES, there  is no  known way  to decrypt it.
  16950.                          The data is lost.
  16951.  
  16952.                      2.  When choosing  keys, avoid  anything obvious
  16953.                          that someone else might easily guess.  E.g.,
  16954.                          don't use  just your  name or  your date  of
  16955.                          birth or  a common  word.  Instead, choose a
  16956.                          key  with   a  seemingly   random   mix   of
  16957.                          alphanumeric and punctuation characters.
  16958.  
  16959.                      3.  No encryption  system should  be  considered
  16960.                          perfectly secure.   Although  there  are  no
  16961.                          known practical  methods for  attacking DES,
  16962.                          such methods may exist.
  16963.  
  16964.                      4.  Encryption  can  only  protect  data  that's
  16965.                          actually encrypted.   If  you have copies of
  16966.                          the clear  text on  your disk,  anyone  with
  16967.                          access to  your machine  may be able to read
  16968.                          the  data.    Also,  even  when  a  file  is
  16969.                          deleted, the  contents may  remain  on  your
  16970.  
  16971.  
  16972.  
  16973.  
  16974.                                      Page 267
  16975.  
  16976.      Help
  16977.  
  16978.  
  16979.                          disk, accessible to anyone with knowledge of
  16980.                          the file system.
  16981.  
  16982.                      5.  If you  would  like  to  compress  encrypted
  16983.                          data, e.g.,  with utilities such as PKZip or
  16984.                          ARC, compress  first,  then  encrypt.    The
  16985.                          encryption  process  tends  to  destroy  the
  16986.                          redundancy  in  the  data  that  compression
  16987.                          programs depend on.
  16988.  
  16989.  
  16990.  
  16991.  
  16992.  
  16993.  
  16994.  
  16995.  
  16996.  
  16997.  
  16998.  
  16999.  
  17000.  
  17001.  
  17002.  
  17003.  
  17004.  
  17005.  
  17006.  
  17007.  
  17008.  
  17009.  
  17010.  
  17011.  
  17012.  
  17013.  
  17014.  
  17015.  
  17016.  
  17017.  
  17018.  
  17019.  
  17020.  
  17021.  
  17022.  
  17023.  
  17024.  
  17025.  
  17026.  
  17027.  
  17028.  
  17029.  
  17030.  
  17031.  
  17032.  
  17033.  
  17034.  
  17035.  
  17036.                                      Page 268
  17037.  
  17038.                                                                          Help
  17039.  
  17040.  
  17041.             diff:     Compare Files or Directories
  17042.  
  17043.                  Usage:  diff [-bBefhiqrvw!-] [-m minmatch] [-
  17044.                  Dstring] oldpath newpath
  17045.  
  17046.                     diff produces  a list  of differences between two
  17047.                     files or  directories.  The working assumption is
  17048.                     that newpath  is a newer version of whatever's in
  17049.                     oldpath.   If they're  files, diff  assumes  they
  17050.                     contain ascii  text but  if it  encounters a file
  17051.                     containing lots  of binary data, it switches to a
  17052.                     binary comparison mode to avoid dumping gibberish
  17053.                     to the screen.
  17054.  
  17055.                     Comparing files,  diff looks for minimal sections
  17056.                     of change.  Each difference  is shown  as an add,
  17057.                     delete  or   change  with  the  appropriate  line
  17058.                     numbers or  line number  ranges for   each  file.
  17059.                     Following are  texts of  the  differing  section.
  17060.                     Lines that  have been  deleted are  flagged  with
  17061.                     '<'; lines  that have been added are flagged with
  17062.                     '>'.   Alternately, diff  can be  used to produce
  17063.                     merged listings  with #ifdefs  for the C compiler
  17064.                     or highlighting for quick visual scanning.
  17065.  
  17066.                     Comparing directories,  the lists  of files  they
  17067.                     contain all  the way  down through  the tree  are
  17068.                     sorted, then  compared.   If  the  same  filename
  17069.                     exists in  each directory  tree, a  quick  binary
  17070.                     comparison is  normally made to give a quick yes-
  17071.                     or-no are  they different.   If  -r is specified,
  17072.                     the diff  text comparison is done recursively the
  17073.                     whole way down the two trees.
  17074.  
  17075.                     If one of the arguments to diff is a file and the
  17076.                     other is  a directory,  diff will  look  for  and
  17077.                     compare against  a file  of the  same name in the
  17078.                     directory.
  17079.  
  17080.                  Options:
  17081.  
  17082.                      -b  Blank spaces of any length compare equal.
  17083.                          Ignore any leading or trailing white space
  17084.                          on each line.
  17085.                      -B  Binary comparison even on text files.
  17086.                      -Dstring   Produce a merged #ifdef'ed listing,
  17087.                                 with the string being defined meaning
  17088.                                 use the older version. (Newer version
  17089.                                 is intentionally the default.)
  17090.                      -e  Turn off highlighting of empty lines.  Byt
  17091.                          default, if highlighting is used to show
  17092.                          areeas of change, even empty lines will have
  17093.                          Ansi sequences at the beginning and end so
  17094.                          that if more is used to display the output
  17095.  
  17096.  
  17097.  
  17098.                                      Page 269
  17099.  
  17100.      Help
  17101.  
  17102.  
  17103.                          with the default color stretch mode on,
  17104.                          empty lines will still be highlighted.
  17105.                      -f  Force diff-style comparison to continue even
  17106.                          on files that appear to contain binary data.
  17107.                      -i  Ignore character case.
  17108.                      -m minmatch     Minimum match length to insist
  17109.                                 on before resynchronizing two files.
  17110.                                 (Default is 2 lines.)
  17111.                      -q  Quiet:  supress warnings about files
  17112.                          containing binary data.
  17113.                      -r  Recursively diff the contents of any
  17114.                          subdirectories.
  17115.                      -v  Verbose listing of all the contents of any
  17116.                          entire subdirectory added or deleted.
  17117.                      -h  Help.  (This screen.)
  17118.                      -w  White space is ignored totally.
  17119.                      -!  Produce merged, highlighted version.  Text
  17120.                          that's unchanged is normal, deleted text is
  17121.                          red, new text is green.
  17122.                      --  End of options.
  17123.                      
  17124.                  Colors:
  17125.  
  17126.                     You may  set your  own choices  for screen colors
  17127.                     using these environmental variables:
  17128.  
  17129.                     Name          Use                    Default
  17130.  
  17131.                     COLORS        Normal screen colors   White on
  17132.                     Black
  17133.                     ADDITIONS     Lines added            Bright Green
  17134.                     DELETIONS     Lines deleted          Bright Red
  17135.  
  17136.                     Colors recognized  are black, red, green, yellow,
  17137.                     blue, magenta (or red blue), cyan (or blue green)
  17138.                     or white.   Foreground  colors may also be bright
  17139.                     or blink.   The names of the colors and the words
  17140.                     bright, blink  and on  may be  in either upper or
  17141.                     lower  or   mixed  case  but  the  names  of  the
  17142.                     environmental variables  themselves must  be  all
  17143.                     upper case.
  17144.  
  17145.                     Either or  both  the  foreground  and  background
  17146.                     colors may  be specified;  if you don't specify a
  17147.                     value, it's  considered transparent  and inherits
  17148.                     the  color   underneath  it.       ADDITIONS  and
  17149.                     DELETIONS inherit from COLORS.
  17150.  
  17151.  
  17152.  
  17153.  
  17154.  
  17155.  
  17156.  
  17157.  
  17158.  
  17159.  
  17160.                                      Page 270
  17161.  
  17162.                                                                          Help
  17163.  
  17164.  
  17165.             dim:      Discard any ansi escape sequences in the input
  17166.             stream
  17167.  
  17168.                  Usage:  dim [-h-] [ file1 file2 ... ]
  17169.  
  17170.                     dim deletes  any  ansi  escape  sequences  as  it
  17171.                     copies text  from each  of the  files you specify
  17172.                     onto stdout.  If several files are given, they're
  17173.                     concatenated one after another to the output.
  17174.  
  17175.                     If no files are given, dim reads from stdin.
  17176.  
  17177.                  Options:
  17178.  
  17179.                      -h  Help.  (This screen.)
  17180.                      --  End of options.
  17181.  
  17182.  
  17183.             dirs:     List the Current Directory Stack
  17184.  
  17185.                  Usage:  dirs [-h-]
  17186.  
  17187.                     Show  the   list  of   fully-qualified  directory
  17188.                     pathnames  on   the  current   directory   stack,
  17189.                     highlighting the current disk:directory pair.
  17190.  
  17191.                     Hamilton C  shell maintains  a stack representing
  17192.                     the current  directory and  any previous  current
  17193.                     directories has saved there.
  17194.  
  17195.                     (See also the cd, pushd, popd and rotd commands.)
  17196.  
  17197.                  Options:
  17198.  
  17199.                      -h  Help.
  17200.                      --  End of options.
  17201.  
  17202.  
  17203.  
  17204.  
  17205.  
  17206.  
  17207.  
  17208.  
  17209.  
  17210.  
  17211.  
  17212.  
  17213.  
  17214.  
  17215.  
  17216.  
  17217.  
  17218.  
  17219.  
  17220.  
  17221.  
  17222.                                      Page 271
  17223.  
  17224.      Help
  17225.  
  17226.  
  17227.             dskread:  Read Raw Sectors from a Disk
  17228.  
  17229.                  Usage:  dskread [-bcdhHL-] [-n name] [-N sectors] [-
  17230.                  s size] [-t tracks]
  17231.                            [ disk: ] [ <sectorlist> ]
  17232.  
  17233.                     dskread copies  low-level raw sectors on the disk
  17234.                     you specify to stdout.
  17235.  
  17236.                     In conjunction  with dskwrite,  dskread  is  most
  17237.                     useful as  a quick  diskette duplication utility:
  17238.                     you can  read a  whole diskette image into a file
  17239.                     with  dskread,   then  write  it  back  out  with
  17240.                     dskwrite to a new diskette.  But it's also useful
  17241.                     for restoring a long stream of data dumped across
  17242.                     a series of diskettes with dskwrite.
  17243.  
  17244.                     The disk  is given as a a single alphabetic drive
  17245.                     letter plus  a colon.   If  no disk is specified,
  17246.                     the first  logical  drive  is  assumed  (in  most
  17247.                     machines, this is the a: drive).
  17248.  
  17249.                  Operation:
  17250.  
  17251.                     dskread normally  starts at  cylinder 0,  head 0,
  17252.                     sector  0  and  walks  through  the  whole  disk,
  17253.                     reading all the sectors on a track under one head
  17254.                     and  then   all  tracks   in  a  cylinder  before
  17255.                     repositioning the heads to the next cylinder.
  17256.  
  17257.                     dskread always  reads whole  sectors except  when
  17258.                     reading from a file using the -d option.
  17259.  
  17260.                  Options:
  17261.  
  17262.                      -b  Boot record.  Skip sector 0 on the
  17263.                          assumption it simply contains a standard
  17264.                          boot record and parameter block
  17265.                          corresponding to the particular media.
  17266.                      -c  Continuation.  Assume the data has been
  17267.                          split across several diskettes.  After each
  17268.                          disk has been read, prompt for the next one.
  17269.                          If -d is specified also, the filename
  17270.                          extension on each disk will be the disk
  17271.                          number, i.e., 001, 002, 003, etc.
  17272.                      -d  Dummy filesystem.  Assume the data is in a
  17273.                          single file on the disk.  If neither the -d
  17274.                          nor the -b options is given, the disk will
  17275.                          be read beginning with sector 0.
  17276.                      -h  Help.  (This screen.)
  17277.                      -n <name>  The filename to look for if the -d
  17278.                                 (dummy file- system) option is used.
  17279.                                 Default is `bindata'.
  17280.                      --  End of options.
  17281.  
  17282.  
  17283.  
  17284.                                      Page 272
  17285.  
  17286.                                                                          Help
  17287.  
  17288.  
  17289.                  Formatting:
  17290.  
  17291.                     Default is  to let  OS/2 or  Windows  NT  try  to
  17292.                     determine the  formatting that  was used.  If the
  17293.                     disk was  written in  unusual format  or has non-
  17294.                     standard data  in sector 0, the following options
  17295.                     can be  override OS/2  or Windows NT's attempt to
  17296.                     guess the format:
  17297.  
  17298.                      -H  High density formatting.
  17299.                      -L  Low density formatting.
  17300.                      -N <sectors>    Sectors per track.
  17301.                      -s <size>  Sector size.  Normally only 512 is
  17302.                                 supported but, depending on your
  17303.                                 hardware, you may also be able to
  17304.                                 create 128, 256 or 1024-byte sectors.
  17305.                      -t <tracks>     Number of tracks.
  17306.                      
  17307.                  Sector lists:
  17308.  
  17309.                     Optionally, you can specify a list of sectors you
  17310.                     want written. Sectors are given in
  17311.  
  17312.                         (cylinder, head, sector)
  17313.  
  17314.                     coordinates with parentheses around and commas or
  17315.                     white space  to separate  the numeric  values you
  17316.                     write.   Cylinders, heads and sectors are counted
  17317.                     from zero and can be specified in decimal, hex or
  17318.                     octal.
  17319.  
  17320.                     A single  sector specified  alone means just that
  17321.                     sector. Listing  several separated  by commas  or
  17322.                     spaces means each one individually.
  17323.  
  17324.                     A pair  of sectors  joined by  a hyphen  means  a
  17325.                     range:   all the  consecutive  sectors  beginning
  17326.                     with the first and running through to the second.
  17327.  
  17328.                     Specifying a negative number as an ordinate means
  17329.                     use the highest possible value for that disk.
  17330.  
  17331.                     If any  of the ordinates of a sector are omitted,
  17332.                     they're assumed to be zero exept when it closes a
  17333.                     range, in  which case  it means  use the  highest
  17334.                     possible value.
  17335.  
  17336.                  Examples:
  17337.  
  17338.                      1.  To  duplicate   a  whole   diskette   image,
  17339.                          autoformatting the  output media if it's not
  17340.                          already formatted:
  17341.  
  17342.  
  17343.  
  17344.  
  17345.  
  17346.                                      Page 273
  17347.  
  17348.      Help
  17349.  
  17350.  
  17351.                            % dskread a: > dskimage.a
  17352.                            % dskwrite -av a: < dskimage.a
  17353.  
  17354.                      2.  To use a diskette as a serial archive media:
  17355.                          The -d  option allows  you to  request  just
  17356.                          enough dummy file system ``envelope'' around
  17357.                          the otherwise  arbitrary data  you intend to
  17358.                          write to  ensure the  disk can still be used
  17359.                          with other  OS/2 or  Windows  NT  utilities.
  17360.                          Here's an  example writing  the result  of a
  17361.                          tar'ing (archiving)  a whole  directory to a
  17362.                          series of diskettes, again autoformatting:
  17363.  
  17364.                            % tar -asr mydir < nul | dskwrite -avcd -n
  17365.                         mydir a:
  17366.  
  17367.                          It's restored with
  17368.  
  17369.                            % dskread -dc -n mydir a: | tar -xsr
  17370.  
  17371.                          The diskettes used do not all have to be the
  17372.                          same density;  any mix  of high  and low  is
  17373.                          okay.   But remember  that if  a disk  isn't
  17374.                          already  formatted,   there's  no   way  for
  17375.                          dskwrite to  tell whether  it should be high
  17376.                          or low  density; any  disks it has to format
  17377.                          will all be formatted the same way.
  17378.  
  17379.                          If putting  the greatest  possible amount of
  17380.                          data on  a diskette  is more  important than
  17381.                          compatibility with  other OS/2 or Windows NT
  17382.                          utilities,  you   can  also  use  the  space
  17383.                          normally devoted  to the FAT file system and
  17384.                          even the boot sector.  Here is the same tar,
  17385.                          written  to   a  series   of   autoformatted
  17386.                          high-density diskettes where every sector is
  17387.                          used for data:
  17388.  
  17389.                            % tar -asr mydir < nul | dskwrite -avcHx
  17390.                         a:
  17391.  
  17392.                          It's restored with
  17393.  
  17394.                            % dskread -cH a: | tar -xsr
  17395.  
  17396.                          Since no  labeling of the data is written to
  17397.                          the diskette, it's the user's responsibility
  17398.                          to   keep track  of the  order in  which the
  17399.                          disks were  written and even what format was
  17400.                          used.
  17401.  
  17402.  
  17403.  
  17404.  
  17405.  
  17406.  
  17407.  
  17408.                                      Page 274
  17409.  
  17410.                                                                          Help
  17411.  
  17412.  
  17413.             dskwrite: Write Raw Sectors to a Disk
  17414.  
  17415.                  Usage:  dskwrite [-abcdfFhHLTvxz-] [-Z!] [-n name]
  17416.                  [-N sectors] [-s size] [-t tracks]
  17417.                            [-V volid] [ disk: ] [ <sectorlist> ]
  17418.  
  17419.                     dskwrite  copies   stdin  to  the  low-level  raw
  17420.                     sectors on the disk you specify.
  17421.  
  17422.                     In conjunction  with dskread,  dskwrite  is  most
  17423.                     useful as  a quick  diskette duplication utility:
  17424.                     you can  read a  whole diskette image into a file
  17425.                     with  dskread,   then  write  it  back  out  with
  17426.                     dskwrite to a new diskette.  But it's also useful
  17427.                     for dumping a long stream of data across a series
  17428.                     of diskettes, formatting and filling each as much
  17429.                     as possible before requesting the next one.
  17430.  
  17431.                     The disk  is given as a a single alphabetic drive
  17432.                     letter plus  a colon.   If  no disk is specified,
  17433.                     the first  logical drive  is assumed.   (In  most
  17434.                     machines, this is the a: drive.)
  17435.  
  17436.                  Operation:
  17437.  
  17438.                     dskwrite normally  starts at  cylinder 0, head 0,
  17439.                     sector  0  and  walks  through  the  whole  disk,
  17440.                     writing all the sectors on a track under one head
  17441.                     and  then   all  tracks   in  a  cylinder  before
  17442.                     repositioning the  heads to  the  next  cylinder.
  17443.                     You can  also cause  dskwrite to  write  to  just
  17444.                     specific sectors by giving it a sector list.
  17445.  
  17446.                     dskwrite always  writes  whole  sectors  and,  if
  17447.                     requested, formats  whole tracks.   If  the  last
  17448.                     sector is  only partially-used, dskwrite fills it
  17449.                     out with binary zeros.
  17450.  
  17451.                     To  avoid   conflicts  with  other  applications,
  17452.                     dskwrite always  locks a  drive  before  actually
  17453.                     writing to it.
  17454.  
  17455.                  Basic Options:
  17456.  
  17457.                      -a  Autoformat.  If the disk appears to be
  17458.                          unformatted, automatically do a low-level
  17459.                          format of the entire disk.
  17460.                      -f  Low-level format the entire disk as data is
  17461.                          copied to it from stdin.
  17462.                      -F  Low-level format the entire disk and create
  17463.                          an empty FAT filesystem.  Do not read
  17464.                          anything from stdin.
  17465.                      -v  Verify.  Read back and verify each write.
  17466.                      -h  Help.  (This screen.)
  17467.  
  17468.  
  17469.  
  17470.                                      Page 275
  17471.  
  17472.      Help
  17473.  
  17474.  
  17475.                      --  End of options.
  17476.  
  17477.  
  17478.  
  17479.  
  17480.  
  17481.  
  17482.  
  17483.  
  17484.  
  17485.  
  17486.  
  17487.  
  17488.  
  17489.  
  17490.  
  17491.  
  17492.  
  17493.  
  17494.  
  17495.  
  17496.  
  17497.  
  17498.  
  17499.  
  17500.  
  17501.  
  17502.  
  17503.  
  17504.  
  17505.  
  17506.  
  17507.  
  17508.  
  17509.  
  17510.  
  17511.  
  17512.  
  17513.  
  17514.  
  17515.  
  17516.  
  17517.  
  17518.  
  17519.  
  17520.  
  17521.  
  17522.  
  17523.  
  17524.  
  17525.  
  17526.  
  17527.  
  17528.  
  17529.  
  17530.  
  17531.  
  17532.                                      Page 276
  17533.  
  17534.                                                                          Help
  17535.  
  17536.  
  17537.                  Options for using the disk as a serial media:
  17538.  
  17539.                      -b  Boot record.  Write a simple non-system disk
  17540.                          boot record and parameter block
  17541.                          corresponding to the particular media into
  17542.                          sector 0.  If writing the entire disk,
  17543.                          continue with the next sector.
  17544.                      -c  Continuation.  If there's more data on stdin
  17545.                          after an entire disk has been written,
  17546.                          prompt for a new disk to be inserted and
  17547.                          continue.  If -d is specified also, the
  17548.                          filename extension on each disk will be the
  17549.                          disk number, i.e., 001, 002, 003, etc.
  17550.                      -d  Dummy filesystem.  Write a boot record and a
  17551.                          FAT filesystem into the initial sectors
  17552.                          allocating whatever is written to a single
  17553.                          file.
  17554.                      -n <name>  The filename to be given to any data
  17555.                                 written onto the disk if the -d
  17556.                                 (dummy filesystem) option is used.
  17557.                                 Default is 'bindata'.
  17558.                      
  17559.                  Formatting:
  17560.  
  17561.                     Default is  to let  OS/2 or  Windows  NT  try  to
  17562.                     determine how  the media  has been  formatted and
  17563.                     not to reformat the disk.
  17564.  
  17565.                     If the  disk isn't  already formatted  and the -a
  17566.                     (autoformat) option  is selected or if formatting
  17567.                     is  explicitly   requested  with  the  -f  or  -F
  17568.                     options, dskwrite  will do  a low-level format of
  17569.                     the media.
  17570.  
  17571.                     dskwrite takes  its specification  of the  format
  17572.                     (e.g., low-  or high-density)  from the following
  17573.                     sources, in decreasing priority:
  17574.  
  17575.                      1.  Explicit specifications on the command line.
  17576.                      2.  The OS/2 or Windows NT kernel's guess at the
  17577.                          media format, assuming the disk is already
  17578.                          formatted and not being re-formatted.
  17579.                      3.  The format parameters in the boot sector
  17580.                          copied from stdin, assuming neither the -b
  17581.                          nor the -d options is given.
  17582.                      4.  The previous format of the media, assuming
  17583.                          it's already formatted in a standard
  17584.                          configuration but being reformatted.
  17585.                      5.  The highest-density format supported by the
  17586.                          drive.
  17587.                      
  17588.                     Unless you specify -b or -d, dskwrite will expect
  17589.                     to  copy  a  compatible  disk  image  from  stdin
  17590.                     including a  suitable boot  sector,  etc.    That
  17591.  
  17592.  
  17593.  
  17594.                                      Page 277
  17595.  
  17596.      Help
  17597.  
  17598.  
  17599.                     happens automatically  when dskread'ing  a  whole
  17600.                     disk is paired with dskwrite'ing a whole disk but
  17601.                     not otherwise.
  17602.  
  17603.  
  17604.  
  17605.  
  17606.  
  17607.  
  17608.  
  17609.  
  17610.  
  17611.  
  17612.  
  17613.  
  17614.  
  17615.  
  17616.  
  17617.  
  17618.  
  17619.  
  17620.  
  17621.  
  17622.  
  17623.  
  17624.  
  17625.  
  17626.  
  17627.  
  17628.  
  17629.  
  17630.  
  17631.  
  17632.  
  17633.  
  17634.  
  17635.  
  17636.  
  17637.  
  17638.  
  17639.  
  17640.  
  17641.  
  17642.  
  17643.  
  17644.  
  17645.  
  17646.  
  17647.  
  17648.  
  17649.  
  17650.  
  17651.  
  17652.  
  17653.  
  17654.  
  17655.  
  17656.                                      Page 278
  17657.  
  17658.                                                                          Help
  17659.  
  17660.  
  17661.                  Explicit Format Specification Options:
  17662.  
  17663.                      -H  High density format.
  17664.                      -L  Low density format.
  17665.                      -N <sectors>    Sectors per track.
  17666.                      -s <size>  Sector size.  Normally only 512 is
  17667.                                 supported but, depending on your
  17668.                                 hardware, you may also be able to
  17669.                                 create 128, 256 or 1024-byte sectors.
  17670.                      -t <tracks>     Number of tracks.
  17671.                      
  17672.                     Other Advanced Options:
  17673.  
  17674.                      -T  Low-level format the media track-at-a-time
  17675.                          as the disk is written.  Only as much of the
  17676.                          disk as is being written to will be
  17677.                          formatted.
  17678.                      -V <volid> The volume identifier to be written
  17679.                                 into the dummy filesystem header if
  17680.                                 -F or -d is used.  (Ignored
  17681.                                 otherwise.)
  17682.                      -x  Force use of a non-standard format or
  17683.                          writing of non-standard format parameters to
  17684.                          the boot sector.
  17685.                      -z  Zero-length files written with -d option
  17686.                          should still be added to the directory.
  17687.                          (Otherwise, they're ignored.)
  17688.                      -Z! Force write to a hard disk.  Warning! Very
  17689.                          risky unless you know exactly what you're
  17690.                          doing.
  17691.                      
  17692.                  Sector lists:
  17693.  
  17694.                     Optionally, you can specify a list of sectors you
  17695.                     want written. Sectors are given in
  17696.  
  17697.                         (cylinder, head, sector)
  17698.  
  17699.                     coordinates with parentheses around and commas or
  17700.                     white space  to separate  the numeric  values you
  17701.                     write.   Cylinders, heads and sectors are counted
  17702.                     from zero and can be specified in decimal, hex or
  17703.                     octal.
  17704.  
  17705.                     A single  sector specified  alone means just that
  17706.                     sector. Listing  several separated  by commas  or
  17707.                     spaces means each one individually.
  17708.  
  17709.                     A pair  of sectors  joined by  a hyphen  means  a
  17710.                     range:   all the  consecutive  sectors  beginning
  17711.                     with the first and running through to the second.
  17712.  
  17713.                     Specifying a negative number as an ordinate means
  17714.                     use the highest possible value for that disk.
  17715.  
  17716.  
  17717.  
  17718.                                      Page 279
  17719.  
  17720.      Help
  17721.  
  17722.  
  17723.                     If any  of the ordinates of a sector are omitted,
  17724.                     they're assumed to be zero exept when it closes a
  17725.                     range, in  which case  it means  use the  highest
  17726.                     possible value.
  17727.  
  17728.                  Examples:
  17729.  
  17730.                      1.  To  duplicate   a  whole   diskette   image,
  17731.                          autoformatting the  output media if it's not
  17732.                          already formatted:
  17733.  
  17734.                            % dskread a: > dskimage.a
  17735.                            % dskwrite -av a: < dskimage.a
  17736.  
  17737.                      2.  To use  dskwrite to  format a  disk with  an
  17738.                          empty FAT file system, use either:
  17739.  
  17740.                            % dskwrite -F a:
  17741.  
  17742.                          or:
  17743.  
  17744.                            % dskwrite -df a: <nul
  17745.  
  17746.                      3.  To rewrite just the boot sector to make it a
  17747.                          non-system disk:
  17748.  
  17749.                            % dskwrite -b a: <nul
  17750.  
  17751.                      4.  To use a diskette as a serial archive media:
  17752.  
  17753.                          The -d  option allows  you to  request  just
  17754.                          enough dummy file system ``envelope'' around
  17755.                          the otherwise  arbitrary data  you intend to
  17756.                          write to  ensure the  disk can still be used
  17757.                          with other  OS/2 or  Windows  NT  utilities.
  17758.                          Here's an  example writing  the result  of a
  17759.                          tar'ing (archiving)  a whole  directory to a
  17760.                          series of diskettes, again autoformatting:
  17761.  
  17762.                            % tar -asr mydir < nul | dskwrite -avcd -n
  17763.                         mydir a:
  17764.  
  17765.                          It's restored with
  17766.  
  17767.                            % dskread -dc -n mydir a: | tar -xsr
  17768.  
  17769.                          The diskettes used do not all have to be the
  17770.                          same density;  any mix  of high  and low  is
  17771.                          okay.   But remember  that if  a disk  isn't
  17772.                          already  formatted,   there's  no   way  for
  17773.                          dskwrite to  tell whether  it should be high
  17774.                          or low  density; any  disks it has to format
  17775.                          will all be formatted the same way.
  17776.  
  17777.  
  17778.  
  17779.  
  17780.                                      Page 280
  17781.  
  17782.                                                                          Help
  17783.  
  17784.  
  17785.                          If putting  the greatest  possible amount of
  17786.                          data on  a diskette  is more  important than
  17787.                          compatibility with  other OS/2 or Windows NT
  17788.                          utilities,  you   can  also  use  the  space
  17789.                          normally devoted  to the FAT file system and
  17790.                          even the boot sector.  Here is the same tar,
  17791.                          written to  a series  of autoformatted high-
  17792.                          density diskettes where every sector is used
  17793.                          for data:
  17794.  
  17795.                            % tar -asr mydir < nul | dskwrite -avcHx
  17796.                         a:
  17797.  
  17798.                          It's restored with
  17799.  
  17800.                            % dskread -cH a: | tar -xsr
  17801.  
  17802.                          Since no  labeling of the data is written to
  17803.                          the diskette, it's the user's responsibility
  17804.                          to   keep track  of the  order in  which the
  17805.                          disks were  written and even what format was
  17806.                          used.
  17807.  
  17808.                  Non-standard Diskette Formats:
  17809.  
  17810.                     If you  write anything but a standard boot record
  17811.                     into the  boot sector,  you will  not be  able to
  17812.                     read it  with anything  but dskread and even then
  17813.                     only if  you tell  it explicitly what what format
  17814.                     was used.   Without a standard parameter block in
  17815.                     the boot  sector, the  the OS/2  and  Windows  NT
  17816.                     diskette device  drivers just  can't tell  on its
  17817.                     own how the diskette was written.
  17818.  
  17819.                     Similarly, it's possible you may be able to write
  17820.                     a non-standard  format (e.g., a sector size other
  17821.                     than 512 bytes, etc.) depending on your hardware.
  17822.                     But doing  that may  make the diskette impossible
  17823.                     to read on other machines.
  17824.  
  17825.                     For that  reason, dskwrite normally won't let you
  17826.                     write a boot record that doesn't match the actual
  17827.                     format of  the diskette nor will it let you write
  17828.                     anything other  than one  of the standard format.
  17829.                     To override  these checks,  you must  use the  -x
  17830.                     option.
  17831.  
  17832.                  Writing to a Hard Disk:
  17833.  
  17834.                     Deliberately, dskwrite  normally  only  lets  you
  17835.                     write to diskettes.
  17836.  
  17837.                     Writing to  a hard  disk is  very risky since the
  17838.                     chance of  catastrophic loss of information is so
  17839.  
  17840.  
  17841.  
  17842.                                      Page 281
  17843.  
  17844.      Help
  17845.  
  17846.  
  17847.                     high.   Also, only ESDI and SCSI disk controllers
  17848.                     routinely map out bad blocks, so reading the disk
  17849.                     image from one drive and writing it to another is
  17850.                     unlikely to  work if  there  are  bad  blocks  on
  17851.                     either one.
  17852.  
  17853.                     To force  dskwrite to  write to  a hard disk, you
  17854.                     must specify  the -Z! option, meant to be hard to
  17855.                     accidentally type.     In effect,  the -Z! option
  17856.                     means you understand the risk you're taking.
  17857.  
  17858.  
  17859.  
  17860.  
  17861.  
  17862.  
  17863.  
  17864.  
  17865.  
  17866.  
  17867.  
  17868.  
  17869.  
  17870.  
  17871.  
  17872.  
  17873.  
  17874.  
  17875.  
  17876.  
  17877.  
  17878.  
  17879.  
  17880.  
  17881.  
  17882.  
  17883.  
  17884.  
  17885.  
  17886.  
  17887.  
  17888.  
  17889.  
  17890.  
  17891.  
  17892.  
  17893.  
  17894.  
  17895.  
  17896.  
  17897.  
  17898.  
  17899.  
  17900.  
  17901.  
  17902.  
  17903.  
  17904.                                      Page 282
  17905.  
  17906.                                                                          Help
  17907.  
  17908.  
  17909.             du:       List Disk Usage Statistics
  17910.  
  17911.                  Usage:  du [-acdxvh] [ disk1 disk2 ... ]
  17912.  
  17913.                     du prints  statistics showing the total, used and
  17914.                     free space  on each  disk partition.  If no disks
  17915.                     are  specified,   du  looks   for   a   DRIVEMASK
  17916.                     environmental variable  that can  be used to mask
  17917.                     off just  the  drive  you  want  reported.    The
  17918.                     DRIVEMASK  is   specified  as  a  list  of  drive
  17919.                     letters; ranges  are allowed.  Otherwise, all the
  17920.                     fixed  disk  partitions  beginning  with  c:  are
  17921.                     reported.   The  current  disk's  statistics  are
  17922.                     highlighted.   Sizes  are  normally  reported  in
  17923.                     binary (1000*1024) megabytes.
  17924.  
  17925.                  Option:
  17926.  
  17927.                      -a  If no disks are specified, report on all
  17928.                          disks.
  17929.                      -c  If no disks are specified, report on just
  17930.                          the current disk.
  17931.                      -d  Report in decimal (1,000,000) megabytes.
  17932.                      -x  Report in hex (1024*1024) megabytes.
  17933.                      -v  Give detailed cluster information.
  17934.                      -h  Help.
  17935.                      --  End of options.
  17936.                      
  17937.                     Name          Use                    Default
  17938.  
  17939.                     COLORS        Normal screen colors   White on
  17940.                     Black
  17941.                     HIGHLIGHT     Current disk or directory.  Bright
  17942.  
  17943.                     Colors recognized  are black, red, green, yellow,
  17944.                     blue, magenta (or red blue), cyan (or blue green)
  17945.                     or white.   Foreground  colors may also be bright
  17946.                     or blink.   The names of the colors and the words
  17947.                     bright, blink  and on  may be  in either upper or
  17948.                     lower  or   mixed  case  but  the  names  of  the
  17949.                     environmental variables  themselves must  be  all
  17950.                     upper case.
  17951.  
  17952.                     Either or  both  the  foreground  and  background
  17953.                     colors may  be specified;  if you don't specify a
  17954.                     value, it's  considered transparent  and inherits
  17955.                     the color  underneath it.     HIGHLIGHT  inherits
  17956.                     from COLORS.
  17957.  
  17958.  
  17959.  
  17960.  
  17961.  
  17962.  
  17963.  
  17964.  
  17965.  
  17966.                                      Page 283
  17967.  
  17968.      Help
  17969.  
  17970.  
  17971.             echo:     Echo the Arguments to Standard Output
  17972.  
  17973.                  Usage:  echo [-n2h-] [ text ]
  17974.  
  17975.                     Echo the  text to  standard output  (or  stderr),
  17976.                     substituting  for   certain  character  sequences
  17977.                     preceded  by   the  escapesym   character.   (The
  17978.                     escapesym character  is normally  `^' but  can be
  17979.                     changed with the set command.)
  17980.  
  17981.                        ^a  Audible Alert (Bell)   ^r  Carriage Return
  17982.                        ^b  BackSpace              ^t  Tab
  17983.                        ^f  Form Feed              ^v  Vertical Tab
  17984.                        ^n  NewLine                ^^  Single
  17985.                     escapesym
  17986.  
  17987.                     The escapesym character may also be followed with
  17988.                     the numeric  value of  the intended  substitution
  17989.                     character where the value is specified in hex (as
  17990.                     an 'x' followed by hex digits) or in octal.
  17991.  
  17992.                  Options:
  17993.  
  17994.                      -n  Don't automatically append a Carriage
  17995.                          Return/Line Feed sequence to the end of the
  17996.                          output.
  17997.                      -2  Write to stderr instead of stdout.
  17998.                      -h  Help.
  17999.                      --  End of options.
  18000.  
  18001.  
  18002.  
  18003.  
  18004.  
  18005.  
  18006.  
  18007.  
  18008.  
  18009.  
  18010.  
  18011.  
  18012.  
  18013.  
  18014.  
  18015.  
  18016.  
  18017.  
  18018.  
  18019.  
  18020.  
  18021.  
  18022.  
  18023.  
  18024.  
  18025.  
  18026.  
  18027.  
  18028.                                      Page 284
  18029.  
  18030.                                                                          Help
  18031.  
  18032.  
  18033.             eval:     Parse & Evaluate at Run-Time
  18034.  
  18035.                  Usage:  eval [delta] [-irfth-] [ argument words ]
  18036.  
  18037.                     Evaluate the  words following on the command line
  18038.                     as text  to be parsed and evaluated as statements
  18039.                     only after  all the substitutions and wildcarding
  18040.                     have been  done.   Optionally, under  OS/2,  eval
  18041.                     lets you  run the  command at  a higher  or lower
  18042.                     scheduling priority.
  18043.  
  18044.                     Command or variable substitutions aren't normally
  18045.                     done until  after statements  have  already  been
  18046.                     parsed and compiled into an internal form and, if
  18047.                     it's a  background statement,  passed  off  to  a
  18048.                     background child thread.
  18049.  
  18050.                     The eval command is useful if either:
  18051.  
  18052.                      -   You want command or variable substitutions
  18053.                          to be recognized as any of the reserved
  18054.                          words of the language or as an alias, or
  18055.                      -   You want the substitutions done before a
  18056.                          background thread is started, or
  18057.                      -   You want to run the command at a different
  18058.                          priority.
  18059.  
  18060.                  Options:
  18061.  
  18062.                      -i  Idle time priority.  (In Unix terms, this is
  18063.                          the ``nice'' option:  if you're nice, you
  18064.                          run at idle priority and let everything else
  18065.                          run ahead of you.)
  18066.                      -r  Regular priority.  (The usual initial
  18067.                          value.)
  18068.                      -f  Foreground priority.
  18069.                      -t  Time critical priority.
  18070.                      delta      A signed integer amount by which the
  18071.                                 scheduling priority for this command
  18072.                                 is to be adjusted up or down.  The
  18073.                                 `+' or `-' sign is required to
  18074.                                 distinguish this as an option.
  18075.                                 Priority ranges from 0 to 31 and is
  18076.                                 normally 0 when the C shell starts up
  18077.                                 or if a new priority class is chosen.
  18078.                                 Attempting to set priority below 0 or
  18079.                                 above the maximum results in priority
  18080.                                 0 or 31 respectively.
  18081.                      -h  Help.
  18082.                      --  End of options.
  18083.  
  18084.  
  18085.  
  18086.  
  18087.  
  18088.  
  18089.  
  18090.                                      Page 285
  18091.  
  18092.      Help
  18093.  
  18094.  
  18095.             fgrep:    Fast string search (fast grep) of text files
  18096.  
  18097.                  Usage:  fgrep [-hbcilnqsvwx-] [-f ptrnfile] [
  18098.                  pattern ] [ file1 file2 ...]
  18099.  
  18100.                     fgrep does  a quick,  deliberately simple  string
  18101.                     search.  It does not use regular expressions, but
  18102.                     does have  some diff-style  options for  ignoring
  18103.                     upper-/lower-case differences  or treating  white
  18104.                     spaces of any length as equal, etc.  You can also
  18105.                     give it  a list of strings you want searched for,
  18106.                     one per line in a pattern file or via stdin.
  18107.  
  18108.                     Each matching  line is copied to stdout.  If more
  18109.                     than one  file is  being searched,  each line  is
  18110.                     preceded by  the name  of file  where  the  match
  18111.                     occurred plus a `:' character.
  18112.  
  18113.                  Options:
  18114.  
  18115.                      -h  Help.  (This screen.)
  18116.                      -b  Blank spaces of any length compare equal.
  18117.                          Ignore any leading or trailing white space
  18118.                          on each line.
  18119.                      -c  Just print a count of the number of lines
  18120.                          which match.
  18121.                      -f ptrnfile  Read the patterns from a file.
  18122.                      -i  Ignore character case.
  18123.                      -l  Show just the names of any files containing
  18124.                          at least one match.  Show each name only
  18125.                          once, each on a separate line.
  18126.                      -n  Show the line numbers of any matches.
  18127.                      -q  Quiet:  don't show filenames where the
  18128.                          matches occur.
  18129.                      -s  Read the patterns from stdin.
  18130.                      -v  Invert the pattern:  show all lines except
  18131.                          those that match.
  18132.                      -w  White space is ignored totally.
  18133.                      -x  Exact match:  the whole line must match the
  18134.                          pattern.
  18135.                      --  End of options.
  18136.  
  18137.  
  18138.  
  18139.  
  18140.  
  18141.  
  18142.  
  18143.  
  18144.  
  18145.  
  18146.  
  18147.  
  18148.  
  18149.  
  18150.  
  18151.  
  18152.                                      Page 286
  18153.  
  18154.                                                                          Help
  18155.  
  18156.  
  18157.             grep:     Regular expression pattern search of text files
  18158.  
  18159.                  Usage:  grep [-hcilnqsv-] [-f ptrnfile] [ pattern ]
  18160.                  [ file1 file2 ...]
  18161.  
  18162.                     grep  uses   special  patterns   called   regular
  18163.                     expressions to filter what it reads from stdin or
  18164.                     from any files you specify.
  18165.  
  18166.                     Regular expressions are written in this notation,
  18167.                     in decreasing precedence:
  18168.  
  18169.                      c          Any ordinary character matches
  18170.                                 itself.
  18171.                      \c         Match the literal character c.
  18172.                      ^          Beginning of line.
  18173.                      $          End of line.
  18174.                      .          Match any single character.
  18175.                      [...]      Match any single character in the
  18176.                                 list.
  18177.                      [^...]     Match any single character not in the
  18178.                                 list.
  18179.                      \n         Match whatever literal text the n'th
  18180.                                 tagged \(...\) expression matched.
  18181.                      r*         Match zero or more occurrences of r.
  18182.                      r1r2       Match expression r1 followed by r2.
  18183.                      \(r\)      Tagged regular expression.  Match the
  18184.                                 pattern inside the \(...\), and
  18185.                                 remember the literal text that
  18186.                                 matched.
  18187.                      
  18188.                     A regular expression pattern cannot contain Null,
  18189.                     NewLine or CarriageReturn characters.
  18190.  
  18191.                     When typing  a regular  expression on the command
  18192.                     line, remember  that $,  [, ],  ^, (  and )  have
  18193.                     special meaning  to Hamilton  C shell. Put single
  18194.                     quotes around the string to turn off that special
  18195.                     meaning.   Also, even  inside quotes,  type ^^ to
  18196.                     mean ^ except when it immediately follows [.
  18197.  
  18198.                     Each matching  line is copied to stdout.  If more
  18199.                     than one  file is  being searched,  each line  is
  18200.                     preceded by  the name  of file  where the matched
  18201.                     occurred plus a `:' character.
  18202.  
  18203.                  Options:
  18204.  
  18205.                      -h  Help.  (This screen.)
  18206.                      -c  Just print a count of the number of lines
  18207.                          which match.
  18208.                      -f ptrnfile     Read the patterns from a file.
  18209.                      -i  Ignore character case.
  18210.  
  18211.  
  18212.  
  18213.  
  18214.                                      Page 287
  18215.  
  18216.      Help
  18217.  
  18218.  
  18219.                      -l  Show just the names of any files containing
  18220.                          at least one match.  Show each name only
  18221.                          once, each on a separate line.
  18222.                      -n  Show the line numbers of any matches.
  18223.                      -q  Quiet:  don't show filenames where the
  18224.                          matches occur.
  18225.                      -s  Read the patterns from stdin.
  18226.                      -v  Invert the pattern:  show all lines except
  18227.                          those that match.
  18228.                      --  End of options.
  18229.  
  18230.  
  18231.             hashstat: Print Path Hashing Performance Statistics
  18232.  
  18233.                  Usage:  hashstat [-h-]
  18234.  
  18235.                     Summarize the  recent effectiveness  of the  path
  18236.                     hashing mechanism.
  18237.  
  18238.                     Hamilton C shell uses a hashing mechanism to help
  18239.                     it decide  which path  directories  and  filetype
  18240.                     extensions should tried first when looking for an
  18241.                     executable file.   This  way, it  avoids  wasting
  18242.                     time with  requests to  the OS/2 or NT kernels to
  18243.                     look for files that are known to be non-existent.
  18244.                     Sometimes, the first guess made this way is wrong
  18245.                     (the  hash  says  a  file  might  exist,  but  it
  18246.                     doesn't) and  the shell  has to  try again with a
  18247.                     different directory or extension.
  18248.  
  18249.                     hashstat shows  you the  hit rate,  which is  the
  18250.                     number of  hits divided  by the  number of  tries
  18251.                     (hits plus  misses.)   Blindspots are  files that
  18252.                     aren't found  using the  hash but  are found on a
  18253.                     second  pass,   using   an   exhaustive   search.
  18254.                     Blindspots happen  when you  add new  files to  a
  18255.                     path directory;  when detected,  they  cause  the
  18256.                     directory to be rehashed.
  18257.  
  18258.                     (See also the rehash and unhash commands.)
  18259.  
  18260.                  Options:
  18261.  
  18262.                      -h  Help.
  18263.                      --  End of options.
  18264.  
  18265.  
  18266.  
  18267.  
  18268.  
  18269.  
  18270.  
  18271.  
  18272.  
  18273.  
  18274.  
  18275.  
  18276.                                      Page 288
  18277.  
  18278.                                                                          Help
  18279.  
  18280.  
  18281.             head:     Copy the first few lines or bytes of a file to
  18282.             Stdout
  18283.  
  18284.                  Usage:  head [-hbnq<size>-] [-t<tabs>][ file1 file2
  18285.                  ... ]
  18286.  
  18287.                     head copies  the first  part of each of the files
  18288.                     you specify  onto stdout.   If  several files are
  18289.                     given, each is announced unless you specify quiet
  18290.                     mode.  You may specify how much to read from each
  18291.                     file in  either lines  or bytes.  If no files are
  18292.                     given, head reads from stdin.
  18293.  
  18294.                  Options:
  18295.  
  18296.                      -h  Help.  (This screen.)
  18297.                      -c  Count characters.  (Default is lines.)
  18298.                      -q  Quiet mode.  Don't announce the name of each
  18299.                          file as it's read.
  18300.                      -<size>    Amount to be read from each file.
  18301.                                 (Default is 10 lines or 512 bytes.)
  18302.                      -t<tabs>   Tab settings to use for viewing text.
  18303.                                 (Default is to use value given by the
  18304.                                 TABS environment variable or, if
  18305.                                 that's undefined, to do no tab
  18306.                                 expansion.)
  18307.                      -n  No tab expansion.
  18308.                      --  End of options.
  18309.  
  18310.  
  18311.             heapstat: Print Heap Usage Statistics
  18312.  
  18313.                  Usage:  heapstat [-h-]
  18314.  
  18315.                     Summarize  the  current  heap  usage,  i.e.,  the
  18316.                     number of  objects allocated  on the heap and the
  18317.                     total storage used.  Heapstats are only available
  18318.                     if they  were enabled with the -H option when the
  18319.                     shell was  started. Because  of  the  significant
  18320.                     performance penalty associated with tracking heap
  18321.                     usage, heapstats are not normally enabled.
  18322.  
  18323.                  Options:
  18324.  
  18325.                      -h  Help.
  18326.                      --  End of options.
  18327.  
  18328.  
  18329.  
  18330.  
  18331.  
  18332.  
  18333.  
  18334.  
  18335.  
  18336.  
  18337.  
  18338.                                      Page 289
  18339.  
  18340.      Help
  18341.  
  18342.  
  18343.             history:  Display the History List
  18344.  
  18345.                  Usage:  history [-srh-] [ n [m] ]
  18346.  
  18347.                     Display commands  from the  history list.   If no
  18348.                     operands are  given, show  the entire list.  If a
  18349.                     single integer `n' is specified, display the last
  18350.                     n commands.   If  both integers  `n' and  `m' are
  18351.                     given, then:
  18352.  
  18353.                        if m >= n:    Display  commands   numbered   n
  18354.                                  through m.
  18355.  
  18356.                        if m < n: Display  m  commands,  beginning  at
  18357.                                  command n.
  18358.  
  18359.                     (The size  of  the  list  is  controlled  by  the
  18360.                     history variable, changed using the set command.)
  18361.  
  18362.                  Options:
  18363.  
  18364.                      -s  Short form:  Leave off the command numbers.
  18365.                      -r  Reverse order:  Show the oldest first.
  18366.                      -h  Help.
  18367.                      --  End of options.
  18368.  
  18369.  
  18370.             kill:     Kill Specified Process or Thread Activity
  18371.  
  18372.                  Usage:  kill [-xh-] scheduling_id  [ scheduling_id
  18373.                  ... ]
  18374.  
  18375.                     Terminate specific  activities.   Normally,  only
  18376.                     direct child  screen groups  and processes can be
  18377.                     killed.   Only certain  threads will respond to a
  18378.                     kill;  you   cannot  inadvertently   kill  normal
  18379.                     internal housekeeping.
  18380.  
  18381.                     Scheduling_ids are  the thread, process or screen
  18382.                     group identifiers  as reported by the ps command.
  18383.                     An id  beginning with `t' indicates a thread; `p'
  18384.                     indicates  a  process;  `s'  indicates  a  screen
  18385.                     group.  (Screen groups are only on OS/2.)
  18386.  
  18387.                  Options:
  18388.  
  18389.                      -x  Kill even processes that are not direct
  18390.                          children.  (Has no effect on OS/2 screen
  18391.                          groups that are not direct children; this is
  18392.                          an OS/2 kernel restriction.)
  18393.                      -h  Help.
  18394.                      --  End of options.
  18395.  
  18396.  
  18397.  
  18398.  
  18399.  
  18400.                                      Page 290
  18401.  
  18402.                                                                          Help
  18403.  
  18404.  
  18405.             label:    Read/Write the Volume Label
  18406.  
  18407.                  Usage:  label [-h-]  [ disk: ] [ label ]
  18408.  
  18409.                     label reads  or writes the label on the specified
  18410.                     disk, given  as a  single alphabetic drive letter
  18411.                     plus a  colon.   If no  disk  is  specified,  the
  18412.                     current  disk   is  assumed.    If  no  label  is
  18413.                     specified, the  current label  name  is  printed.
  18414.                     Otherwise  label   tries  to  set  the  label  to
  18415.                     specified name.   Spacing  between the  disk: and
  18416.                     the label operands is optional.
  18417.  
  18418.                     The principal  differences between  this and  the
  18419.                     standard OS/2 or NT label command are that (1) it
  18420.                     can be  invoked directly  from the  C shell  (the
  18421.                     standard OS/2 label had a bug in its command line
  18422.                     processing that  meant it  had to be invoked only
  18423.                     via cmd.exe), and (2) it never prompts, making it
  18424.                     more suitable in scripts.
  18425.  
  18426.                  Options:
  18427.  
  18428.                      -h  Help.  (This screen.)
  18429.                      --  End of options.
  18430.  
  18431.  
  18432.  
  18433.  
  18434.  
  18435.  
  18436.  
  18437.  
  18438.  
  18439.  
  18440.  
  18441.  
  18442.  
  18443.  
  18444.  
  18445.  
  18446.  
  18447.  
  18448.  
  18449.  
  18450.  
  18451.  
  18452.  
  18453.  
  18454.  
  18455.  
  18456.  
  18457.  
  18458.  
  18459.  
  18460.  
  18461.  
  18462.                                      Page 291
  18463.  
  18464.      Help
  18465.  
  18466.  
  18467.              ls:      List Files or Directories
  18468.  
  18469.                  Usage:  ls [-+][lL!rqhx- ndtsez mU DHSARa 0-9 wME]
  18470.                  path1 [ path2 ... ]
  18471.  
  18472.                     ls lists  the  specified  files  or  directories.
  18473.                     Directory names  are highlighted;  names of files
  18474.                     or directories  with the system bit set are shown
  18475.                     in green.
  18476.  
  18477.                     File and  directory names  are normally converted
  18478.                     to lower  case for  better readability.   But  ls
  18479.                     will  look   for   an   environmental   variable,
  18480.                     MIXEDCASEDRIVES, giving  a list  of drives, e.g.,
  18481.                     f-hq, meaning  drives F: through H: and drive Q:,
  18482.                     which should be displayed in mixed case.
  18483.  
  18484.                     To customize  ls with  a default behavior of your
  18485.                     own choosing,  use  the  LSOPTIONS  environmental
  18486.                     variable.   ls will  first  process  any  options
  18487.                     specified in  LSOPTIONS before  any specified  on
  18488.                     the command line.
  18489.  
  18490.                  General Options:
  18491.  
  18492.                      -l  Long format listings of the files or
  18493.                          directories.
  18494.                      -L  Very Long format listings.  (Under OS/2 1.1,
  18495.                          used and allocated media space is always
  18496.                          reported.  Under 1.2, the size of any
  18497.                          extended attributes is shown instead of
  18498.                          media space if -E is specified.  Also, under
  18499.                          1.2, root directories do not have a
  18500.                          timestamp and are reported as midnight,
  18501.                          Jan 1, 1980)
  18502.                      -!  List just the names specified, not the
  18503.                          contents of any directories.  (Remember to
  18504.                          type this option at the end of the list so
  18505.                          the space afterward will prevent it being
  18506.                          confused as a history reference.)
  18507.                      -r  Recursively list contents of any
  18508.                          subdirectories.
  18509.                      -q  Quiet.  Don't generate an error message for
  18510.                          non-existent files.
  18511.                      -h  Help (short list.)
  18512.                      -hx Extended help (this description.)
  18513.                      --  End of options.  (Useful if filenames start
  18514.                          with ``-''.)
  18515.                      
  18516.  
  18517.  
  18518.  
  18519.  
  18520.  
  18521.  
  18522.  
  18523.  
  18524.                                      Page 292
  18525.  
  18526.                                                                          Help
  18527.  
  18528.  
  18529.                  Sorting Options:
  18530.  
  18531.                     Sorts may  be done in any order; default is -nds.
  18532.                     (The filename is the most important sort criteria
  18533.                     and ties are broken by date or size.)
  18534.  
  18535.                      -n  Name (lowest alphabetic first.)
  18536.                      -d  Date (oldest first.)
  18537.                      -t  Time (newest first; same as -dz)
  18538.                      -s  Size (largest first.)
  18539.                      -e  Extension (lowest alphabetic first.)
  18540.                      -z  Reverse the major or last specified sort.
  18541.                      -m  Merge the listings of directories and files.
  18542.                      -U  Unordered (in order of appearance in the
  18543.                          directory.)
  18544.                      
  18545.                  Selection Criteria:
  18546.  
  18547.                      +<type> Include files/directories fitting this
  18548.                              pattern.
  18549.                      -<type> Leave out anything fitting this pattern.
  18550.                  
  18551.                     where  <type>   is   combination   of   following
  18552.                     characters:
  18553.  
  18554.                      D   Directories.
  18555.                      H   Hidden files or directories.
  18556.                      S   System files or directories.
  18557.                      A   Archive bit set.
  18558.                      R   Read-only files or directories.
  18559.                      .   ``.'' and ``..'' files.
  18560.                      a   All files or directories regardless of
  18561.                          attributes.
  18562.                  
  18563.                     The  default   is  ``+a  -.  -H'',  meaning  list
  18564.                     anything other  than ``.''  and ``..'' not marked
  18565.                     Hidden.       Anything   specified    is    added
  18566.                     to/subtracted  from   this  set.     Ordering  of
  18567.                     additions or subtractions does make a difference.
  18568.                     If  the   slash,  ``/'',  is  used  to  introduce
  18569.                     options, it  is treated  as a plus when used with
  18570.                     selection criteria.
  18571.  
  18572.                     Selection  criteria   normally  applies  only  to
  18573.                     directories  and   files  found   by  listing   a
  18574.                     directory.   All names  given on the command line
  18575.                     will  be  listed  if  they  exist  regardless  of
  18576.                     whether they  match the selection criteria unless
  18577.                     the -c option is specified.
  18578.  
  18579.                      -c  Command line names must match criteria also,
  18580.                          unless only one name is given.
  18581.  
  18582.  
  18583.  
  18584.  
  18585.  
  18586.                                      Page 293
  18587.  
  18588.      Help
  18589.  
  18590.  
  18591.                  Listing Options:
  18592.  
  18593.                      -<integer> Specified number of columns.
  18594.                      -0  Standard multi-columns on an 80-column
  18595.                          screen.
  18596.                      -C  Capitalization.  Display filenames in the
  18597.                          upper- or lower-case characters actually
  18598.                          stored in the file system.
  18599.                      -w  Walk subdirectories to show true sizes in
  18600.                          long format listings.
  18601.                      -M  Media allocation is shown instead of amount
  18602.                          used with -l.
  18603.                      -E  Extended attribute size is shown instead of
  18604.                          media allocation with -L.  (-E is ignored
  18605.                          under OS/2 1.1.)
  18606.                      
  18607.                  Colors:
  18608.  
  18609.                     You may  set your  own choices  for screen colors
  18610.                     using these environmental variables:
  18611.  
  18612.                     Name          Use                    Default
  18613.  
  18614.                     COLORS        Normal screen colors   White on
  18615.                     Black
  18616.                     DIRECTORIES   Directories            Bright
  18617.                     SYSTEMFILES   Files with system bit set   Green
  18618.                     SYSTEMDIRS    Directories with system     (see
  18619.                     below)
  18620.                                   bit set
  18621.  
  18622.                     Colors recognized  are black, red, green, yellow,
  18623.                     blue, magenta (or red blue), cyan (or blue green)
  18624.                     or white.   Foreground  colors may also be bright
  18625.                     or blink.   The names of the colors and the words
  18626.                     bright, blink  and on  may be  in either upper or
  18627.                     lower  or   mixed  case  but  the  names  of  the
  18628.                     environmental variables  themselves must  be  all
  18629.                     upper case.
  18630.  
  18631.                     Either or  both  the  foreground  and  background
  18632.                     colors may  be specified;  if you don't specify a
  18633.                     value, it's  considered transparent  and inherits
  18634.                     the color underneath it.
  18635.  
  18636.                     SYSTEMDIRS normally inherits a merging of the
  18637.                     DIRECTORIES and SYSTEMFILES colors. DIRECTORIES
  18638.                     and SYSTEMFILES inherit from COLORS.
  18639.  
  18640.  
  18641.  
  18642.  
  18643.  
  18644.  
  18645.  
  18646.  
  18647.  
  18648.                                      Page 294
  18649.  
  18650.                                                                          Help
  18651.  
  18652.  
  18653.             markexe:  Mark the application type bits in an .exe file
  18654.  
  18655.                  Usage:  markexe [-ftpzslh-] file1 [ file2 ... ]
  18656.  
  18657.                     markexe reports or sets the application type bits
  18658.                     on  OS/2   .exe  files   to  indicate   how   the
  18659.                     application should be started, i.e., whether they
  18660.                     must run full-screen, can run in a text window or
  18661.                     must be started as full PM graphics applications.
  18662.  
  18663.                     If the  .exe is a 16-bit application, markexe can
  18664.                     also be used to indicate whether it supports long
  18665.                     filenames.   (All 32-bit  applications  must,  by
  18666.                     definition, support long filenames.)
  18667.  
  18668.                     If no flags are specified, the types are reported
  18669.                     but not altered.
  18670.  
  18671.                  Application Types:
  18672.  
  18673.                      -f  Full-screen.
  18674.                      -t  Text windowable.
  18675.                      -p  PM graphics.
  18676.                      -z  Zero the type bits.  (Undefined type.)
  18677.                      
  18678.                  Long Filename Support (ignored for 32-bit .exe
  18679.                  files):
  18680.  
  18681.                      -s  Short filenames only.
  18682.                      -l  Long (HPFS-style) filenames supported.
  18683.                      
  18684.                  Other Options:
  18685.  
  18686.                      -h  Help.  (This screen.)
  18687.                      --  End of options.
  18688.  
  18689.  
  18690.             mkdir:    Make Directories
  18691.  
  18692.                  Usage:  mkdir [-h-] directory1 [ directory2 ... ]
  18693.  
  18694.                  Options:
  18695.  
  18696.                      -h  Help.
  18697.                      --  End of options.
  18698.  
  18699.  
  18700.  
  18701.  
  18702.  
  18703.  
  18704.  
  18705.  
  18706.  
  18707.  
  18708.  
  18709.  
  18710.                                      Page 295
  18711.  
  18712.      Help
  18713.  
  18714.  
  18715.             more:     A Better More Filter
  18716.  
  18717.                  Usage:  more [-#IinNcvbodxCh-] [-rradix] [-ttabs]
  18718.                  [-sscroll]
  18719.                            [file1 file2 ... ]
  18720.  
  18721.                     This more  provides a  number of  advantages over
  18722.                     the standard  more.com filter.  It's faster, goes
  18723.                     backwards and forwards through a file, can search
  18724.                     for character  strings and  display  binary  data
  18725.                     embedded in  the text.   As  it reads  a file, it
  18726.                     builds an  ISAM structure on-the-fly that lets it
  18727.                     jump   to   a   specific   line   number   almost
  18728.                     instantaneously.   It's designed  for  very  fast
  18729.                     browsing.
  18730.  
  18731.                     On-line help  is available to the key bindings by
  18732.                     pressing ``h''  when you see the Press H for Help
  18733.                     prompt at the bottom of a screenful of data.
  18734.  
  18735.                     For  OS/2,   there  are  two  versions  of  more:
  18736.                     more.exe is  built in  small model  and can cache
  18737.                     about  11K   characters;  a   ``huge''   version,
  18738.                     moreh.exe, is  built in  large  model  and  while
  18739.                     slightly slower,  can cache  about 4M characters.
  18740.                     Where speed  is less important than being able to
  18741.                     scroll all the way back through a large amount of
  18742.                     text coming  through a pipe, use moreh.exe, which
  18743.                     was compiled in large model.
  18744.  
  18745.                  Options:
  18746.  
  18747.                      -#  Show line numbers.
  18748.                      -I  Start up in case-independent search mode.
  18749.                      -i  Go into Interactive mode immediately, which
  18750.                          means clear the screen first for faster
  18751.                          painting and put up the Press H for Help
  18752.                          prompt rather than just exiting if there's
  18753.                          less than a screenful of input.
  18754.                      -n  Next file option.  Pressing space bar when
  18755.                          the end-of-file message is displayed causes
  18756.                          more to continue with the next file or to
  18757.                          exit if there are no more files.
  18758.                      -N  No stretch.  Don't stretch color changes out
  18759.                          to the right edge of the screen.
  18760.                      -c  Show non-printables in C language style.
  18761.                      -v  Make non-printables Visible as control
  18762.                          characters.
  18763.                      -b  Show Binary values of non-printable
  18764.                          characters.
  18765.                      -o  Use Octal for binary data.
  18766.                      -d  Use Decimal for binary data.
  18767.                      -x  Use Hexadecimal for binary data.
  18768.  
  18769.  
  18770.  
  18771.  
  18772.                                      Page 296
  18773.  
  18774.                                                                          Help
  18775.  
  18776.  
  18777.                      -C  Don't clear the screen before each new
  18778.                          screenful.
  18779.                      -rradix    Use user-specified radix for binary
  18780.                          data.
  18781.                      -ttabs     Set tabs every integer number of
  18782.                          spaces.
  18783.                      -sscroll   Set the integer default scroll
  18784.                          amount.
  18785.                      --  End of options.  (Useful if a filename
  18786.                          begins with ``-''.)
  18787.                  
  18788.                     Initial tab  settings and  radix values are taken
  18789.                     from the  environmental TABS  and RADIX variables
  18790.                     if they're  defined.   Otherwise, TABS  =  8  and
  18791.                     RADIX = 16 is assumed.
  18792.  
  18793.                  Colors:
  18794.  
  18795.                     You may  set your  own choices  for screen colors
  18796.                     using these environmental variables:
  18797.  
  18798.                     Name          Use                    Default
  18799.  
  18800.                     COLORS        Normal screen colors   White on
  18801.                     Black
  18802.                     MOREEOF       End or Top of File messages Green
  18803.                     MORETOPMEM    Top of Memory message  Bright
  18804.                     Yellow
  18805.                     MOREPROMPT    Prompt line at the bottom   Green
  18806.                     MOREFILLIN    Characters typed at the     White
  18807.                                   prompt
  18808.                     MOREERROR     Unrecognizable command Bright
  18809.                     Yellow
  18810.                                   errors
  18811.  
  18812.                     Colors recognized  are black, red, green, yellow,
  18813.                     blue, magenta (or red blue), cyan (or blue green)
  18814.                     or white.   Foreground  colors may also be bright
  18815.                     or blink.   The names of the colors and the words
  18816.                     bright, blink  and on  may be  in either upper or
  18817.                     lower  or   mixed  case  but  the  names  of  the
  18818.                     environmental variables  themselves must  be  all
  18819.                     upper case.
  18820.  
  18821.                     Either or  both  the  foreground  and  background
  18822.                     colors may  be specified;  if you don't specify a
  18823.                     value, it's  considered transparent  and inherits
  18824.                     the  color   underneath  it.       MOREERROR  and
  18825.                     MOREFILLIN inherit  from MOREPROMPT.  MOREPROMPT,
  18826.                     MORETOPMEM and MOREEOF inherit from COLORS.
  18827.  
  18828.  
  18829.  
  18830.  
  18831.  
  18832.  
  18833.  
  18834.                                      Page 297
  18835.  
  18836.      Help
  18837.  
  18838.  
  18839.             mt:       Manipulate the Tape Device  (Windows NT only)
  18840.  
  18841.                  Usage:  mt [-hv-] [-f device] command1 [ command2
  18842.                  ... ]
  18843.  
  18844.                     mt is  used to  give commands to the tape device.
  18845.                     If  a   device  is   not  specified,  the  device
  18846.                     specified by  the TAPE  environment  variable  is
  18847.                     used.  If TAPE is not defined, \\.\tape0 is used.
  18848.                     By default, each command is performed once.  Many
  18849.                     operations may  be performed  multiple  times  by
  18850.                     specifying a count.
  18851.  
  18852.                     These are  the available  commands.  Only as many
  18853.                     characters as are required to uniquely identify a
  18854.                     command need  be  given.    If  no  commands  are
  18855.                     specified, status is given.
  18856.  
  18857.                        fss [n]        Forward space n setmarks.
  18858.                        fsqs [n]       Forward space to n sequential
  18859.                                       setmarks.
  18860.                        fsf [n]        Forward space n filemarks.
  18861.                        fsqf [n]       Forward space to n sequential
  18862.                                       filemarks.
  18863.                        fsr [n]        Forward space n records.
  18864.  
  18865.                        bss [n]        Back space n setmarks.
  18866.                        bsqs [n]       Back space to n sequential
  18867.                                       setmarks.
  18868.                        bsf [n]        Back space n filemark.
  18869.                        bsqf [n]       Back space to n sequential
  18870.                                       filemarks.
  18871.                        bsr [n]        Back space n records.
  18872.  
  18873.                        stp [n [p]]    Set tape position to block n in
  18874.                                       partition p.  Default is block
  18875.                                       1 in current partition.
  18876.                        stpa [n]       Set tape position absolute.  Go
  18877.                                       to block n counting from the
  18878.                                       beginning of the tape.
  18879.  
  18880.                        eod [p]        Goto to end of data in
  18881.                                       partition p.
  18882.                        weod           Write end of data at current
  18883.                                       position.
  18884.  
  18885.                        wfm [n]        Write n filemarks.
  18886.                        wsfm [n]       Write n short filemarks.
  18887.                        wlfm [n]       Write n long filemarks.
  18888.                        wsm [n]        Write n setmarks.
  18889.  
  18890.                        rewind         Rewind the tape.
  18891.                        load           Load the tape and move to the
  18892.                                       beginning.
  18893.  
  18894.  
  18895.  
  18896.                                      Page 298
  18897.  
  18898.                                                                          Help
  18899.  
  18900.  
  18901.                        lock           Lock the tape ejection
  18902.                                       mechanism.
  18903.                        tension        Adjust tension by moving to the
  18904.                                       end of tape and then rewinding.
  18905.                        unload         Rewind and unload the tape.
  18906.                        unlock         Unlock the tape ejection
  18907.                                       mechanism.
  18908.  
  18909.                        blksize [n]    Set blocksize. (Default is
  18910.                                       device default.)
  18911.  
  18912.                        compress [n]   Enable (1) or disable (0)
  18913.                                       compression.
  18914.  
  18915.                        ecc [n]        Enable (1) or disable (0) ECC.
  18916.  
  18917.                        setmarks [1]   Enable (1) or disable (0)
  18918.                                       setmark reporting.
  18919.  
  18920.                        warning [1]    Set end-of-tape warning size.
  18921.  
  18922.                        padding [1]    Enable (1) or disable (0) data
  18923.                                       padding.
  18924.  
  18925.                        status         Print status information about
  18926.                                       the tape device.
  18927.  
  18928.                        erase          Erase from current position to
  18929.                                       end of partition.
  18930.  
  18931.                        create [n [size]]  Create partitions of device
  18932.                                       default number and size.
  18933.                                       Default number and size are
  18934.                                       determined by the device.
  18935.  
  18936.                  Options:
  18937.  
  18938.                      -h  Help.  (This screen.)
  18939.                      -v  Verbose.  Status command should dump out
  18940.                          complete drive and media parameters.
  18941.                          Default is to give just brief status and
  18942.                          position information.
  18943.                      -f device  Name of the tape device to open.
  18944.                      --  End of options.
  18945.  
  18946.  
  18947.  
  18948.  
  18949.  
  18950.  
  18951.  
  18952.  
  18953.  
  18954.  
  18955.  
  18956.  
  18957.  
  18958.                                      Page 299
  18959.  
  18960.      Help
  18961.  
  18962.  
  18963.             mv:       Move Files or Directories
  18964.  
  18965.                  Usage:  mv [-filmh-] source1 [ source2 ... ]
  18966.                  destination
  18967.  
  18968.                     mv is  an intelligent  file or  directory  mover.
  18969.                     It's able  to move either files or directories as
  18970.                     objects regardless  of  whether  the  source  and
  18971.                     destination are in the same directory or even the
  18972.                     same drive.
  18973.  
  18974.                     Files being  moved anywhere on the same partition
  18975.                     are simply  renamed; the  data stays where it is.
  18976.                     Moving a file to a different partition is done by
  18977.                     copying the  file and then deleting the original.
  18978.                     If you  move a  directory but  it keeps  the same
  18979.                     parent, that  also is  a simple rename.  Moving a
  18980.                     directory to  a new  parent is done by a mkdir in
  18981.                     the new  parent  and  moving  all  the  directory
  18982.                     contents using the same ``rename where possible''
  18983.                     strategy recursively.
  18984.  
  18985.                  Options:
  18986.  
  18987.                      -f  Force read-only files to be overwritten.
  18988.                      -i  Interactive:  ask before moving each object
  18989.                          on the command line.
  18990.                      -l  Logging is on:  display the name of each
  18991.                          file or directory
  18992.                      -m  Merge sub-directories of same name in source
  18993.                          and destination.
  18994.                      -h  Help.
  18995.                      --  End of options.  (Useful if filenames start
  18996.                          with ``-''.)
  18997.  
  18998.  
  18999.             newer:    Test whether file1 is newer than all the others
  19000.  
  19001.                  Usage:  newer [-h-] [ file1 file2 ... ]
  19002.  
  19003.                     Prints ``1''  if file1 is newer, otherwise prints
  19004.                     ``0''.
  19005.  
  19006.                  Options:
  19007.  
  19008.                      -h  Help.
  19009.                      --  End of options.
  19010.  
  19011.  
  19012.  
  19013.  
  19014.  
  19015.  
  19016.  
  19017.  
  19018.  
  19019.  
  19020.                                      Page 300
  19021.  
  19022.                                                                          Help
  19023.  
  19024.  
  19025.             older:    Test whether file1 is older than all the others
  19026.  
  19027.                  Usage:  older [-h-] [ file1 file2 ... ]
  19028.  
  19029.                     Prints ``1''  if file1 is older, otherwise prints
  19030.                     ``0''.
  19031.  
  19032.                  Options:
  19033.  
  19034.                      -h  Help.
  19035.                      --  End of options.
  19036.  
  19037.  
  19038.             patchlnk: Patch ``The linker bug''  (OS/2 only)
  19039.  
  19040.                  Usage:  patchlnk [-hcw-] filename
  19041.  
  19042.                     patchlnk can  be used  to patch a specific bug in
  19043.                     your linker  if you're  having  problems  linking
  19044.                     under the Hamilton C shell on OS/2. (See also the
  19045.                     discussion under ``Known Bugs'' in the readme.too
  19046.                     file sent with Hamilton C shell.)
  19047.  
  19048.                     If you're  having problems  linking long lists of
  19049.                     .obj files,  you  should  save  a  copy  of  your
  19050.                     link.exe the  way it  is, then  patch your linker
  19051.                     with this  program and  see if  the problem  goes
  19052.                     away.
  19053.  
  19054.                     Microsoft has  discovered they  had a  bug in the
  19055.                     version of  the C  library used  to  build  their
  19056.                     link.exe releases  (roughly) 5.01.21 through (and
  19057.                     possibly past)  5.03.   In the file open routine,
  19058.                     they had  an ``off  by one  error''  that  caused
  19059.                     problems  if   the  DosSetMaxFH   (maximum   file
  19060.                     handles) parameter  for the  process allowed more
  19061.                     than 20  file handles  to be open.  There's a JLE
  19062.                     (0x7e) that  should have  been a  JB (0x72).   It
  19063.                     occurs in the following byte string (in hex):
  19064.  
  19065.                       3b 06 ?? ?? 7e 0d 9a
  19066.  
  19067.                     where the  ?'s mark bytes that can change because
  19068.                     they refer  to data  locations that move from one
  19069.                     build of link.exe to the next.  
  19070.  
  19071.                     (Since the  problem is  in the  MS C library, the
  19072.                     bug could  affect any  C program  that  tries  to
  19073.                     simultaneously  open  20  or  more  handles  with
  19074.                     stdio.   So far,  MS link.exe is only application
  19075.                     known to  do this  but  there  could  be  others.
  19076.                     patchlnk should  work on  them also  and probably
  19077.                     even on your MS C library .lib files.)
  19078.  
  19079.  
  19080.  
  19081.  
  19082.                                      Page 301
  19083.  
  19084.      Help
  19085.  
  19086.  
  19087.                     patchlnk will  scan through the file, looking for
  19088.                     occurrences, which  it will report as hex offsets
  19089.                     from the start of the file you name.  You can use
  19090.                     these numbers  to go examine the file with IBM/MS
  19091.                     patch.exe  if   you  like  and  make  the  change
  19092.                     manually.
  19093.  
  19094.                     You can  also ask  patchlnk to  make the  change,
  19095.                     using the  -w (write) option.  Nothing fancy.  It
  19096.                     just changes the first occurrence and quits.  (If
  19097.                     you really  think you  want any other occurrences
  19098.                     patched, just  keep rerunning  this.) If  want to
  19099.                     look for changes already made, use -c.
  19100.  
  19101.                  Options:
  19102.  
  19103.                      -h  Help.  (This screen.)
  19104.                      -c  Look for changes already made.
  19105.                      -w  Write the first change.
  19106.                      --  End of options.
  19107.  
  19108.  
  19109.             popd:     Pop a new Current Directory and Disk off the
  19110.             Stack
  19111.  
  19112.                  Usage:  popd [-dsh-] [ n ]
  19113.  
  19114.                     Pop an  integer n directory paths from the top of
  19115.                     the stack,  making the  top one remaining the new
  19116.                     current directory and disk.  The default for n is
  19117.                     1.
  19118.  
  19119.                     (See also the cd, dirs, pushd and rotd commands.)
  19120.  
  19121.                  Options:
  19122.  
  19123.                      -d  Discard just stack entry n, counting from 0
  19124.                          at the top, popping everything below it up
  19125.                          one level
  19126.                      -s  Silent.  Don't print the resulting directory
  19127.                          stack.
  19128.                      -h  Help.
  19129.                      --  End of options.
  19130.  
  19131.  
  19132.  
  19133.  
  19134.  
  19135.  
  19136.  
  19137.  
  19138.  
  19139.  
  19140.  
  19141.  
  19142.  
  19143.  
  19144.                                      Page 302
  19145.  
  19146.                                                                          Help
  19147.  
  19148.  
  19149.             ps:       Print Process & Thread Status
  19150.  
  19151.                  Usage:  ps [-h-]
  19152.  
  19153.                     Show the  status of  all the  screen groups (OS/2
  19154.                     only), processes  and  threads  related  to  this
  19155.                     invocation of  Hamilton C shell, highlighting the
  19156.                     current thread.
  19157.  
  19158.                     Screen groups are created when a command you type
  19159.                     requires a  different style  of  window  than  is
  19160.                     currently running.  Screen ids begin with `s'.
  19161.  
  19162.                     Processes are  created when  commands  are  typed
  19163.                     that require  other executable  programs to  run.
  19164.                     Process ids begin with `p'. OS/2 and NT will only
  19165.                     provide information on direct child processes.
  19166.  
  19167.                     Threads are concurrent activities going on inside
  19168.                     Hamilton C  shell.  Some,  such  as  the  cleanup
  19169.                     activities  that   watch  for  other  threads  or
  19170.                     processes to  end always  run in  the background.
  19171.                     Others are  created when  a command requires that
  19172.                     an internal  function be  run in  the background.
  19173.                     Thread ids begin with `t'.
  19174.  
  19175.                  Options:
  19176.  
  19177.                      -h  Help.
  19178.                      --  End of options.
  19179.  
  19180.  
  19181.             pushd:    Push a new Current Directory and Disk onto the
  19182.             Stack
  19183.  
  19184.                  Usage:  pushd [-hs-] [ -c [n] ] [ directory ]
  19185.  
  19186.                     Go to  a new  current directory  and disk, saving
  19187.                     the old  values on  the directory  stack.   If no
  19188.                     operands are  given, swap the top two elements of
  19189.                     the stack.   If the path you specify is just 3 or
  19190.                     more dots,  pushd will  interpret that specially.
  19191.                     Just as  ``..'' means  go up  one level,  ``...''
  19192.                     means up  2 levels,  ``....'' means  up 3 levels,
  19193.                     etc.  If the directory isn't found, the CDPATH is
  19194.                     searched.
  19195.  
  19196.                     (See also the cd, dirs, popd and rotd commands.)
  19197.  
  19198.                  Options:
  19199.  
  19200.                      -c  Copy an item already on the stack onto the
  19201.                          top.  This form takes an optional parameter
  19202.                          n which specifies the integer item number
  19203.  
  19204.  
  19205.  
  19206.                                      Page 303
  19207.  
  19208.      Help
  19209.  
  19210.  
  19211.                          counting from 0 at the top.  Default is
  19212.                          n == 0.
  19213.                      -s  Silent.  Don't print the resulting directory
  19214.                          stack.
  19215.                      -h  Help.
  19216.                      --  End of options.
  19217.  
  19218.  
  19219.  
  19220.  
  19221.  
  19222.  
  19223.  
  19224.  
  19225.  
  19226.  
  19227.  
  19228.  
  19229.  
  19230.  
  19231.  
  19232.  
  19233.  
  19234.  
  19235.  
  19236.  
  19237.  
  19238.  
  19239.  
  19240.  
  19241.  
  19242.  
  19243.  
  19244.  
  19245.  
  19246.  
  19247.  
  19248.  
  19249.  
  19250.  
  19251.  
  19252.  
  19253.  
  19254.  
  19255.  
  19256.  
  19257.  
  19258.  
  19259.  
  19260.  
  19261.  
  19262.  
  19263.  
  19264.  
  19265.  
  19266.  
  19267.  
  19268.                                      Page 304
  19269.  
  19270.                                                                          Help
  19271.  
  19272.  
  19273.             pwd:      Print the Current Working Directories
  19274.  
  19275.                  Usage:  pwd [-ch-] [ disk1 disk2 ... ]
  19276.  
  19277.                     pwd prints a list of the current directories.  If
  19278.                     no disks are specified, pwd looks for a DRIVEMASK
  19279.                     environmental variable  that can  be used to mask
  19280.                     off just  the  drive  you  want  reported.    The
  19281.                     DRIVEMASK  is   specified  as  a  list  of  drive
  19282.                     letters; ranges  are allowed.  Otherwise, all the
  19283.                     fixed  disk  partitions  beginning  with  c:  are
  19284.                     reported.   The current  directory on the current
  19285.                     drive is highlighted.
  19286.  
  19287.                     pwd routinely  reports everything  in lower  case
  19288.                     for better readability.  But pwd will look for an
  19289.                     environmental variable, MIXEDCASEDRIVES, giving a
  19290.                     list of  drives, e.g.,  f-hq, meaning  drives  F:
  19291.                     through  H:   and  drive   Q:,  which  should  be
  19292.                     displayed in mixed case.
  19293.  
  19294.                  Options:
  19295.  
  19296.                      -a  If no disks are specified, report on all
  19297.                          disks.
  19298.                      -c  If no disks are specified, report on just
  19299.                          the current disk.
  19300.                      -h  Help.
  19301.                      --  End of options.
  19302.                      
  19303.                  Colors:
  19304.  
  19305.                     You may  set your  own choices  for screen colors
  19306.                     using these environmental variables:
  19307.  
  19308.                     Name          Use                    Default
  19309.  
  19310.                     COLORS        Normal screen colors   White on
  19311.                     Black
  19312.                     HIGHLIGHT     Current disk           Bright
  19313.  
  19314.                     Colors recognized  are black, red, green, yellow,
  19315.                     blue, magenta (or red blue), cyan (or blue green)
  19316.                     or white.   Foreground  colors may also be bright
  19317.                     or blink.   The names of the colors and the words
  19318.                     bright, blink  and on  may be  in either upper or
  19319.                     lower  or   mixed  case  but  the  names  of  the
  19320.                     environmental variables  themselves must  be  all
  19321.                     upper case.
  19322.  
  19323.                     Either or  both  the  foreground  and  background
  19324.                     colors may  be specified;  if you don't specify a
  19325.                     value, it's  considered transparent  and inherits
  19326.  
  19327.  
  19328.  
  19329.  
  19330.                                      Page 305
  19331.  
  19332.      Help
  19333.  
  19334.  
  19335.                     the color underneath it.  HIGHLIGHT inherits from
  19336.                     COLORS.
  19337.  
  19338.  
  19339.  
  19340.  
  19341.  
  19342.  
  19343.  
  19344.  
  19345.  
  19346.  
  19347.  
  19348.  
  19349.  
  19350.  
  19351.  
  19352.  
  19353.  
  19354.  
  19355.  
  19356.  
  19357.  
  19358.  
  19359.  
  19360.  
  19361.  
  19362.  
  19363.  
  19364.  
  19365.  
  19366.  
  19367.  
  19368.  
  19369.  
  19370.  
  19371.  
  19372.  
  19373.  
  19374.  
  19375.  
  19376.  
  19377.  
  19378.  
  19379.  
  19380.  
  19381.  
  19382.  
  19383.  
  19384.  
  19385.  
  19386.  
  19387.  
  19388.  
  19389.  
  19390.  
  19391.  
  19392.                                      Page 306
  19393.  
  19394.                                                                          Help
  19395.  
  19396.  
  19397.             rehash:   Reinitialize Path Hashing
  19398.  
  19399.                  Usage:  rehash [-h-]
  19400.  
  19401.                     Hamilton C  shell uses  a  hashing  mechanism  to
  19402.                     speed up  searches of  the path  directories.  If
  19403.                     you're  performing  system  administration  work,
  19404.                     moving files  in the  path directories,  the hash
  19405.                     mechanism  may  not  always  reflect  the  latest
  19406.                     changes you've  made.   The rehash command allows
  19407.                     you to  turn re-initialize the hash by re-reading
  19408.                     all the  path directories and setting nohashing =
  19409.                     0.   (The unhash  command can  be  used  to  turn
  19410.                     hashing off.)
  19411.  
  19412.                  Options:
  19413.  
  19414.                      -h  Help.
  19415.                      --  End of options.
  19416.  
  19417.  
  19418.  
  19419.  
  19420.  
  19421.  
  19422.  
  19423.  
  19424.  
  19425.  
  19426.  
  19427.  
  19428.  
  19429.  
  19430.  
  19431.  
  19432.  
  19433.  
  19434.  
  19435.  
  19436.  
  19437.  
  19438.  
  19439.  
  19440.  
  19441.  
  19442.  
  19443.  
  19444.  
  19445.  
  19446.  
  19447.  
  19448.  
  19449.  
  19450.  
  19451.  
  19452.  
  19453.  
  19454.                                      Page 307
  19455.  
  19456.      Help
  19457.  
  19458.  
  19459.             rm:       Remove Files or Directories
  19460.  
  19461.                  Usage:  rm [-rfHSxilh-] pathname1 [ pathname2 ... ]
  19462.  
  19463.                     rm can  delete both  files and  directories.   If
  19464.                     you try  to remove a file with one of the special
  19465.                     mode bits  set (see  chmod) or a directory that's
  19466.                     not empty, it'll refuse unless you use one of the
  19467.                     options to  let it  know that's  really what  you
  19468.                     mean.
  19469.  
  19470.                  Options:
  19471.  
  19472.                      -r  Recursively remove non-empty directories.
  19473.                      -f  Force read-only files or directories to be
  19474.                          removed.
  19475.                      -H  Hidden files or directories can be removed.
  19476.                      -S  System files or directories can be removed.
  19477.                      -x  All of the above.
  19478.                      -i  Interactive:  ask before removing each
  19479.                          object on the command line.
  19480.                      -l  Logging is on:  display the name of each
  19481.                          file or directory as it's removed.
  19482.                      -h  Help.
  19483.                      --  End of options.  (Useful if filenames start
  19484.                          with ``-''.)
  19485.  
  19486.  
  19487.             rmdir:    Remove Directories
  19488.  
  19489.                  Usage:  rmdir [-h-] directory1 [ directory2 ... ]
  19490.  
  19491.                     rmdir will  only remove  empty directories.  Mode
  19492.                     bits (system, hidden or read-only) are ignored.
  19493.  
  19494.                  Options:
  19495.  
  19496.                      -h  Help.
  19497.                      --  End of options.
  19498.  
  19499.  
  19500.  
  19501.  
  19502.  
  19503.  
  19504.  
  19505.  
  19506.  
  19507.  
  19508.  
  19509.  
  19510.  
  19511.  
  19512.  
  19513.  
  19514.  
  19515.  
  19516.                                      Page 308
  19517.  
  19518.                                                                          Help
  19519.  
  19520.  
  19521.             rotd:     Rotate the Directory Stack
  19522.  
  19523.                  Usage:  rotd [-hs-] [ n ]
  19524.  
  19525.                     Rotate  the   directory  stack   an   integer   n
  19526.                     positions.     Positive   values   cause   upward
  19527.                     rotation;   negative    values   cause   downward
  19528.                     rotation.   The default is upward rotation by one
  19529.                     position.)
  19530.  
  19531.                     (See also the cd, dirs, pushd and popd commands.)
  19532.  
  19533.                  Options:
  19534.  
  19535.                      -s  Silent.  Don't print the resulting directory
  19536.                          stack.
  19537.                      -h  Help.
  19538.                      --  End of options.
  19539.  
  19540.  
  19541.             sed:      Stream Editor
  19542.  
  19543.                  Usage:  sed [-hins-] [-f scriptfile ] [-e script] [
  19544.                  script ] [ file1 file2 ...]
  19545.  
  19546.                     sed is  a special  text editor for use on streams
  19547.                     of data  where it  cycles, reading  a  line  from
  19548.                     input, applying  the  editing  operations  you've
  19549.                     specified, and  writing the result to stdout. The
  19550.                     input is  read in  a single pass and each line is
  19551.                     acted on only once.
  19552.  
  19553.                     The  editing  script  can  be  specified  on  the
  19554.                     command line  or, if  it's long and complex, in a
  19555.                     file.   If you  want to  combine a  script on the
  19556.                     command line  with any other script, you must use
  19557.                     the -e  option.  The editing operations available
  19558.                     are the usual search/replace, insert/delete, etc.
  19559.                     With each  operation, you  generally can  specify
  19560.                     the lines  in the file it should affect either by
  19561.                     line number  or matching  a pattern or a range of
  19562.                     lines.
  19563.  
  19564.                  Options:
  19565.  
  19566.                      -h         Help.  (This screen.)
  19567.                      -f scriptfile   Read the script from a file.
  19568.                                 Multiple -f options are allowed and
  19569.                                 the scripts are concatenated.
  19570.                      -e script  Take the following argument word as a
  19571.                                 script.  Multiple -e options are
  19572.                                 allowed.
  19573.                      -i         Ignore character case.
  19574.  
  19575.  
  19576.  
  19577.  
  19578.                                      Page 309
  19579.  
  19580.      Help
  19581.  
  19582.  
  19583.                      -n         Don't automatically write the
  19584.                                 contents of the edit buffer to stdout
  19585.                                 at the end of each cycle.
  19586.                      -s         Read the script from stdin.  (The
  19587.                                 input stream to be edited must be in
  19588.                                 a file.)
  19589.                      --         End of options.
  19590.  
  19591.  
  19592.  
  19593.  
  19594.  
  19595.  
  19596.  
  19597.  
  19598.  
  19599.  
  19600.  
  19601.  
  19602.  
  19603.  
  19604.  
  19605.  
  19606.  
  19607.  
  19608.  
  19609.  
  19610.  
  19611.  
  19612.  
  19613.  
  19614.  
  19615.  
  19616.  
  19617.  
  19618.  
  19619.  
  19620.  
  19621.  
  19622.  
  19623.  
  19624.  
  19625.  
  19626.  
  19627.  
  19628.  
  19629.  
  19630.  
  19631.  
  19632.  
  19633.  
  19634.  
  19635.  
  19636.  
  19637.  
  19638.  
  19639.  
  19640.                                      Page 310
  19641.  
  19642.                                                                          Help
  19643.  
  19644.  
  19645.                  Scripts:
  19646.  
  19647.                     The script  is written  as a  series of commands,
  19648.                     each separated  from the  next by a line end or a
  19649.                     semicolon.  The format of a command is:
  19650.  
  19651.                                 [ address1 [ , address2 ] ] operation
  19652.                      
  19653.                     Spacing between fields is arbitrary:  you can use
  19654.                     spaces or tabs between fields or have none at all
  19655.                     as you prefer.  Here are the fields:
  19656.  
  19657.                      address    is a line number or regular
  19658.                                 expression to be matched.  When a
  19659.                                 regular expression is used as an
  19660.                                 address, it's normally written as
  19661.                                 /regexp/ but it's also possible to
  19662.                                 use the syntax \?regexp? where ? is
  19663.                                 any character.
  19664.                      
  19665.                          Zero- or One-Address Operations:
  19666.                      
  19667.                                 If you don't give an address, the
  19668.                                 operation is applied to all lines.
  19669.                      
  19670.                                 If you give a single address, the
  19671.                                 operation is done on each line that
  19672.                                 matches.
  19673.                      
  19674.                          Ranges:
  19675.                      
  19676.                                 When you give two addresses, you
  19677.                                 define a range. A range can be a
  19678.                                 single line, e.g., ``3,3'', or a
  19679.                                 whole group of lines.  If the
  19680.                                 addresses involve pattern matching,
  19681.                                 e.g., ``/^#ifdef/,/^#endif/'', the
  19682.                                 range might occur over and over in
  19683.                                 the input and will be acted on each
  19684.                                 time.
  19685.                      
  19686.                                 Most operations, e.g.,
  19687.                                 search/replace, are done against all
  19688.                                 lines in the range.  The exceptions
  19689.                                 are i\ (insert), which is acted on at
  19690.                                 entry to the range; a\ (append), and
  19691.                                 q (quit), which are acted on at the
  19692.                                 end; and c\ (change), which deletes
  19693.                                 all the lines in the range but
  19694.                                 doesn't write any output until the
  19695.                                 end of the range.
  19696.                      
  19697.  
  19698.  
  19699.  
  19700.  
  19701.  
  19702.                                      Page 311
  19703.  
  19704.      Help
  19705.  
  19706.  
  19707.                      operation  is one of the 28 basic operations
  19708.                                 provided, together with any arguments
  19709.                                 it takes.
  19710.  
  19711.  
  19712.  
  19713.  
  19714.  
  19715.  
  19716.  
  19717.  
  19718.  
  19719.  
  19720.  
  19721.  
  19722.  
  19723.  
  19724.  
  19725.  
  19726.  
  19727.  
  19728.  
  19729.  
  19730.  
  19731.  
  19732.  
  19733.  
  19734.  
  19735.  
  19736.  
  19737.  
  19738.  
  19739.  
  19740.  
  19741.  
  19742.  
  19743.  
  19744.  
  19745.  
  19746.  
  19747.  
  19748.  
  19749.  
  19750.  
  19751.  
  19752.  
  19753.  
  19754.  
  19755.  
  19756.  
  19757.  
  19758.  
  19759.  
  19760.  
  19761.  
  19762.  
  19763.  
  19764.                                      Page 312
  19765.  
  19766.                                                                          Help
  19767.  
  19768.  
  19769.                  Operations:
  19770.  
  19771.                     There are two buffers in sed: the edit buffer and
  19772.                     the hold  buffer.  Most of the editing operations
  19773.                     work on  the edit  buffer,  doing  search/replace
  19774.                     operations, translating characters, and saving or
  19775.                     retrieving  text   in  the   hold  buffer.    sed
  19776.                     automatically puts  each new  line into  the edit
  19777.                     buffer (along  with its trailing line end) at the
  19778.                     start of  each cycle  unless there  was something
  19779.                     left over after a D (delete head) command.
  19780.  
  19781.                     A second  group of  operations  provide  ways  of
  19782.                     inserting blocks of static text.
  19783.  
  19784.                     The next  group of operations provide rudimentary
  19785.                     ways of  condition-testing and  branching and  of
  19786.                     nesting a series of operations together.
  19787.  
  19788.                     Finally there  operations for  printing and doing
  19789.                     other i/o and   for other miscellaneous things.
  19790.  
  19791.                  Basic Editing:
  19792.  
  19793.                      d          Delete this section.  Start the next
  19794.                                 cycle.
  19795.                      D          Delete from the beginning of edit
  19796.                                 buffer through and including the
  19797.                                 first line ending.  If there's text
  19798.                                 remaining, immediately start over at
  19799.                                 the top of the script without reading
  19800.                                 a new line.
  19801.                      s/.../.../[ngpw]     Search/replace using
  19802.                                 regular expressions. In the replace
  19803.                                 string, ``&'' means whatever the
  19804.                                 search string matched. ``\n'', where
  19805.                                 n is a number, means whatever matched
  19806.                                 that tagged expression in the search
  19807.                                 string.  The search and replace
  19808.                                 strings are shown here delimited with
  19809.                                 /, but you may choose any character
  19810.                                 you like that doesn't occur in either
  19811.                                 string.  The following modifiers are
  19812.                                 accepted:
  19813.                                 n      A decimal number from 1 to
  19814.                                        65,535. Substitute for just
  19815.                                        the n'th occurrence of the
  19816.                                        search pattern.
  19817.                                 g      Global.  Substitute all
  19818.                                        occurrences.
  19819.                                 p      Print the edit buffer if a
  19820.                                        change was made.
  19821.  
  19822.  
  19823.  
  19824.  
  19825.  
  19826.                                      Page 313
  19827.  
  19828.      Help
  19829.  
  19830.  
  19831.                                 w file Write the edit buffer onto the
  19832.                                        end of the file if a change
  19833.                                        was made.
  19834.                      y/.../.../[c]   Translate all occurrences of
  19835.                                 characters in the first string to the
  19836.                                 corresponding characters in the
  19837.                                 second string.  As in the tr utility,
  19838.                                 ranges are allowed, as in
  19839.                                 ``y/a-z/A-Z/''.  The optional ``c''
  19840.                                 flag can be used to complement the
  19841.                                 input range.  Either string can
  19842.                                 contain \r and \n characters.  If the
  19843.                                 first string is longer than the
  19844.                                 second, all the extra characters are
  19845.                                 mapped to the last character in the
  19846.                                 replacement string or to a null if
  19847.                                 there was none.  If the second string
  19848.                                 is longer, the extras are ignored.
  19849.                      
  19850.                  Using the Hold Buffer:
  19851.  
  19852.                      g          Get from the hold buffer.  Replace
  19853.                                 the current contents of the edit
  19854.                                 buffer.
  19855.                      G          Get from the hold buffer and paste
  19856.                                 onto the end of the edit buffer.
  19857.                      h          Hold.  Replace the contents of the
  19858.                                 hold buffer with a copy of the edit
  19859.                                 buffer.
  19860.                      H          Append to hold.  Copy the edit buffer
  19861.                                 contents onto the end of the hold
  19862.                                 buffer.
  19863.                      x          Exchange the edit and hold buffers.
  19864.                      
  19865.                  Inserting blocks of Static Text:
  19866.  
  19867.                      a\ \r\n text    Append the text to the output at
  19868.                                 the end of the cycle if this is the
  19869.                                 last line in the range.  All but the
  19870.                                 last line of text should have a ``\''
  19871.                                 just before the \r\n sequence at the
  19872.                                 end of each line.
  19873.                      c\ \r\n text    Change this section to read as
  19874.                                 shown in the following text.  Start
  19875.                                 the next cycle.
  19876.                      i\ \r\n text    Insert.  Immediately copy the
  19877.                                 following text to stdout if this is
  19878.                                 the start of the range.
  19879.                      
  19880.                  Condition-Testing, Branching and Grouping
  19881.                  operations:
  19882.  
  19883.  
  19884.  
  19885.  
  19886.  
  19887.  
  19888.                                      Page 314
  19889.  
  19890.                                                                          Help
  19891.  
  19892.  
  19893.                      b label    Branch to the label elsewhere in the
  19894.                                 script.  (If no label is given, it's
  19895.                                 to the end of the script.)
  19896.                      q          If this is the end of the range,
  19897.                                 quit.
  19898.                      t label    Branch to the label if search/replace
  19899.                                 changes have been made since the most
  19900.                                 recent input line was read or a t
  19901.                                 operation was run.
  19902.                      : label    Label.  (No address prefix is
  19903.                                 allowed.)
  19904.                      {   }      Group a series of operations
  19905.                                 together.
  19906.                      
  19907.  
  19908.  
  19909.  
  19910.  
  19911.  
  19912.  
  19913.  
  19914.  
  19915.  
  19916.  
  19917.  
  19918.  
  19919.  
  19920.  
  19921.  
  19922.  
  19923.  
  19924.  
  19925.  
  19926.  
  19927.  
  19928.  
  19929.  
  19930.  
  19931.  
  19932.  
  19933.  
  19934.  
  19935.  
  19936.  
  19937.  
  19938.  
  19939.  
  19940.  
  19941.  
  19942.  
  19943.  
  19944.  
  19945.  
  19946.  
  19947.  
  19948.  
  19949.  
  19950.                                      Page 315
  19951.  
  19952.      Help
  19953.  
  19954.  
  19955.                  Printing:
  19956.  
  19957.                      =          Write the line number to stdout.
  19958.                      l          List the contents of the edit buffer
  19959.                                 in C language style with escape
  19960.                                 sequences for binary characters.
  19961.                      p          Print.  Write the contents of the
  19962.                                 edit buffer to stdout.
  19963.                      P          Print from the beginning of the edit
  19964.                                 buffer through and including the
  19965.                                 first line ending.
  19966.                      #n         Suppress any automatic output at the
  19967.                                 end of each cycle.
  19968.                      
  19969.                  Other I/O operations:
  19970.  
  19971.                      n          Next line.  Write the contents of the
  19972.                                 edit buffer to stdout, dump any
  19973.                                 appended text and read a new line
  19974.                                 from stdin to the edit buffer.
  19975.                      N          Read the next line onto the end of
  19976.                                 the edit buffer with a \r\n sequence
  19977.                                 in between.
  19978.                      r file     Copy the contents of this file to
  19979.                                 stdout at the end of the cycle.
  19980.                      w file     Write the edit butter onto the end of
  19981.                                 the file, creating it if it doesn't
  19982.                                 exist.
  19983.                      
  19984.                  Miscellaneous:
  19985.  
  19986.                      ! operation     Don't apply this function unless
  19987.                                 the addressing doesn't match.  Invert
  19988.                                 the line selections.
  19989.                      ;          Null statement.
  19990.                      # comment  Comments and blank lines are ignored.
  19991.                      
  19992.                     If  multiple   a\  (append)   or  r  (read  file)
  19993.                     instructions are  executed (or  the same  one  is
  19994.                     iterated in  a loop),  a new entry is made on the
  19995.                     end of  a list of all the appended text blocks to
  19996.                     be copied  to stdout  at the  end of  the  cycle.
  19997.                     When the end of the cycle is finally reached, the
  19998.                     whole list is dumped, in order from the top.
  19999.  
  20000.  
  20001.  
  20002.  
  20003.  
  20004.  
  20005.  
  20006.  
  20007.  
  20008.  
  20009.  
  20010.  
  20011.  
  20012.                                      Page 316
  20013.  
  20014.                                                                          Help
  20015.  
  20016.  
  20017.                  Regular Expressions:
  20018.  
  20019.                     Search  patterns   are   specified   as   regular
  20020.                     expressions like  those used  by grep.    Regular
  20021.                     expressions are  written  in  this  notation,  in
  20022.                     decreasing precedence:
  20023.  
  20024.                      c          Any ordinary character matches
  20025.                                 itself.
  20026.                      \c         Match the literal character c.
  20027.                      ^          Beginning of line.
  20028.                      $          End of line.
  20029.                      .          Match any single character.
  20030.                      [...]      Match any single character in the
  20031.                                 list.
  20032.                      [^...]     Match any single character not in the
  20033.                                 list.
  20034.                      \n         Match whatever literal text the n'th
  20035.                                 tagged \(...\) expression matched.
  20036.                      r*         Match zero or more occurrences of r.
  20037.                      r1r2       Match expression r1 followed by r2.
  20038.                      \(r\)      Tagged regular expression.  Match the
  20039.                                 pattern inside the \(...\), and
  20040.                                 remember the literal text that
  20041.                                 matched.
  20042.                      
  20043.                     A regular expression pattern cannot contain Nulls
  20044.                     but it  can  contain  NewLine  or  CarriageReturn
  20045.                     characters (which  may be  useful with the N or G
  20046.                     commands.)
  20047.  
  20048.                     When typing  a regular  expression on the command
  20049.                     line, remember  that $,  [, ],  ^, (  and )  have
  20050.                     special meaning  to Hamilton  C shell. Put single
  20051.                     quotes around the string to turn off that special
  20052.                     meaning.   Also, even  inside quotes,  type ^^ to
  20053.                     mean ^ except when it immediately follows [.
  20054.  
  20055.                     Also, / at the beginning of a word on the command
  20056.                     line is  taken as  introducing an option.  If you
  20057.                     mean it  to be  the start  of a  script, use  the
  20058.                     ``--'' option ahead of it.
  20059.  
  20060.  
  20061.  
  20062.  
  20063.  
  20064.  
  20065.  
  20066.  
  20067.  
  20068.  
  20069.  
  20070.  
  20071.  
  20072.  
  20073.  
  20074.                                      Page 317
  20075.  
  20076.      Help
  20077.  
  20078.  
  20079.             setrows:  Set/Report the number of rows in an OS/2 window
  20080.  
  20081.                  Usage:  setrows [-h-] [ rows ]
  20082.  
  20083.                     setrows will  try to  set the  vertical height of
  20084.                     the current  window to  the specified  number  of
  20085.                     rows.  In a PM text window, almost any reasonable
  20086.                     number of  rows can  be chosen,  but full-screen,
  20087.                     you can  choose only  from this set:  12, 14, 21,
  20088.                     23, 24,  25, 27 to 30, 33, 34, 39 to 43, 45 to 50
  20089.                     and 54 to 60.  (Your hardware may not support all
  20090.                     these possibilities.)
  20091.  
  20092.                     If the  number of  rows is not specified, setrows
  20093.                     just reports the current value.
  20094.  
  20095.                     (setrows is supported only on OS/2.)
  20096.  
  20097.                  Options:
  20098.  
  20099.                      -h  Help.  (This screen.)
  20100.                      --  End of options.
  20101.  
  20102.  
  20103.             sleep:    Sleep for a Specified Period
  20104.  
  20105.                  Usage:  sleep [-hm-] [ seconds ]
  20106.  
  20107.                     Sleep the  specified integer  number  of  seconds
  20108.                     (rounded to  the next  clock tick.)  Default is 1
  20109.                     second or until an interrupt occurs.
  20110.  
  20111.                  Options:
  20112.  
  20113.                      -m  Sleep interval is in milliseconds rather
  20114.                          than seconds.
  20115.                      -h  Help.
  20116.                      --  End of options.
  20117.  
  20118.  
  20119.  
  20120.  
  20121.  
  20122.  
  20123.  
  20124.  
  20125.  
  20126.  
  20127.  
  20128.  
  20129.  
  20130.  
  20131.  
  20132.  
  20133.  
  20134.  
  20135.  
  20136.                                      Page 318
  20137.  
  20138.                                                                          Help
  20139.  
  20140.  
  20141.             source:   Read Commands from a File
  20142.  
  20143.                  Usage:  source [-nh-]  filename
  20144.  
  20145.                     Commands are  executed just as if they were typed
  20146.                     directly in  to this  thread of  Hamilton C shell
  20147.                     and  can   change  local  variables  and  current
  20148.                     directory settings.
  20149.  
  20150.                     (This differs  from typing  the name of a C shell
  20151.                     script file  as a  command; if  you  do  that,  a
  20152.                     separate thread is created.)
  20153.  
  20154.                  Options:
  20155.  
  20156.                      -n  No Execute (Just load the history list.)
  20157.                      -h  Help.
  20158.                      --  End of options.
  20159.  
  20160.  
  20161.             split:    Split a Large File into Chunks
  20162.  
  20163.                  Usage:  split [-bhs<size>-] [ infile [prefix] ]
  20164.  
  20165.                     split breaks up a large file into chunks, written
  20166.                     to a  series of output files formed of the prefix
  20167.                     plus a  .nnn extension,  where nnn  is a  3-digit
  20168.                     decimal number.   The  default prefix is 'chunk'.
  20169.                     Each chunk  will be  of the  specified number  of
  20170.                     lines or  bytes.   If only  one operand is given,
  20171.                     it's assumed  to be  the input filename unless -s
  20172.                     is specified.
  20173.  
  20174.                  Options:
  20175.  
  20176.                      -h  Help.  (This screen.)
  20177.                      -b  Count bytes.  (Default is lines.)
  20178.                      -s  Stdin is split.  (Implied if no files are
  20179.                          specified.)
  20180.                      -<size>    Chunk size.  (Defaults are 3000
  20181.                                 lines/300000 bytes.)
  20182.                      --  End of options.
  20183.  
  20184.  
  20185.  
  20186.  
  20187.  
  20188.  
  20189.  
  20190.  
  20191.  
  20192.  
  20193.  
  20194.  
  20195.  
  20196.  
  20197.  
  20198.                                      Page 319
  20199.  
  20200.      Help
  20201.  
  20202.  
  20203.             startwin: Start Win3.x Applications under OS/2 2.x
  20204.  
  20205.                  Usage:  startwin [-h-] [-s type] [ file ] [
  20206.                  arguments ]
  20207.  
  20208.                     Start  the  specified  Win3.x  application  in  a
  20209.                     Virtual DOS  machine using  the  WinStartApp  API
  20210.                     call.   This separate invisible PM application is
  20211.                     used to run the Windows application because:
  20212.  
  20213.                      (a) WinStartApp is the only way to start Win3.x
  20214.                          apps in seamless mode and
  20215.                      (b) the only way to find out when the Win3.x
  20216.                          child started by WinStartApp completes is
  20217.                          via a message queue -- and only PM
  20218.                          applications may have a message queue.
  20219.  
  20220.                     By default,  standard mode is used under OS/2 2.0
  20221.                     and enhanced  mode under  OS/2 2.1.   If seamless
  20222.                     support appears  to be  available, the default is
  20223.                     to run the application in a window using a common
  20224.                     (shared) copy  of the  Windows code; otherwise, a
  20225.                     full-screen Windows session is used by default.
  20226.  
  20227.                     If the  filename specified  to  startwin  is  not
  20228.                     fully-qualified, startwin  will search  for it in
  20229.                     the PATH  directories.  Just as with the C shell,
  20230.                     the current directory will be searched only if it
  20231.                     appears in the PATH list or if the file specified
  20232.                     is clearly a relative path (i.e., it contains a \
  20233.                     or /  or a  drive specification).   If necessary,
  20234.                     startwin will append .exe to the name specified.
  20235.  
  20236.                     startwin is  called automatically  by the C shell
  20237.                     if you type the name of a Win3.x app as a command
  20238.                     under OS/2  2.x.    The  only  reason  you  might
  20239.                     manually invoke startwin would be to override the
  20240.                     default session type.
  20241.  
  20242.                  Options:
  20243.  
  20244.                      -s type    Session type to be used, overriding
  20245.                                 the default type.  Session type
  20246.                                 numbers are as given in the OS/2
  20247.                                 pmshl.h header, including the
  20248.                                 following:
  20249.  
  20250.                          3.0 Standard Full-screen     11
  20251.                          3.0 Standard Seamless VDM    13
  20252.                          3.0 Standard Seamless Common 14 <-2.0
  20253.                          default
  20254.                          3.1 Enhanced Seamless VDM    17
  20255.                          3.1 Enhanced Seamless Common 18 <-2.1
  20256.                          default
  20257.  
  20258.  
  20259.  
  20260.                                      Page 320
  20261.  
  20262.                                                                          Help
  20263.  
  20264.  
  20265.                          3.1 Enhanced Full-screen     19
  20266.  
  20267.                      -h  Help.
  20268.                      --  End of options.
  20269.  
  20270.  
  20271.  
  20272.  
  20273.  
  20274.  
  20275.  
  20276.  
  20277.  
  20278.  
  20279.  
  20280.  
  20281.  
  20282.  
  20283.  
  20284.  
  20285.  
  20286.  
  20287.  
  20288.  
  20289.  
  20290.  
  20291.  
  20292.  
  20293.  
  20294.  
  20295.  
  20296.  
  20297.  
  20298.  
  20299.  
  20300.  
  20301.  
  20302.  
  20303.  
  20304.  
  20305.  
  20306.  
  20307.  
  20308.  
  20309.  
  20310.  
  20311.  
  20312.  
  20313.  
  20314.  
  20315.  
  20316.  
  20317.  
  20318.  
  20319.  
  20320.  
  20321.  
  20322.                                      Page 321
  20323.  
  20324.      Help
  20325.  
  20326.  
  20327.             strings:  Extract ascii strings from a file
  20328.  
  20329.                  Usage:  strings [-habetqvlodx-] [-<min>] [-r<radix>]
  20330.                  [ file1 file2 ... ]
  20331.  
  20332.                     strings will  search for any occurrences of ascii
  20333.                     text in  the files  you give it.  The presumption
  20334.                     is that  the files  are mostly binary and perhaps
  20335.                     quite large,  making it  impractical to  look  at
  20336.                     them directly.
  20337.  
  20338.                     A  string  is  normally  defined  as  4  or  more
  20339.                     printable ascii  characters terminated by a Null,
  20340.                     CarriageReturn, a  NewLine or  a  CarriageReturn-
  20341.                     NewLine  combination.     All   the  white  space
  20342.                     characters  are   considered  printable  and  are
  20343.                     included in  the length  count except  when  they
  20344.                     terminate a  string.   (To C  programmers,  these
  20345.                     printable ascii  characters are the isprint() and
  20346.                     isspace() characters.)
  20347.  
  20348.                     If  you   specify  a  series  of  files,  they're
  20349.                     searched one after the other, each one introduced
  20350.                     by name  unless you  specify Quiet  mode.    Each
  20351.                     string that's found is listed on a separate line.
  20352.                     Note that if a particular string contains NewLine
  20353.                     or  CarriageReturn   characters,   it   will   be
  20354.                     displayed as  a series  of (possibly)  very short
  20355.                     substrings, one per line.
  20356.  
  20357.                  Options:
  20358.  
  20359.                      -h  Help.  (This screen.)
  20360.                      -<min>     Minimum string length to report,
  20361.                                 specified as a decimal integer.
  20362.                      -a  Any string, even if not terminated with a
  20363.                          line ending or a null character.
  20364.                      -t  Trim leading white space from each string.
  20365.                      -b  Discard strings containing only white space.
  20366.                      -e  European characters (accented alphabetics
  20367.                          and European punctuation) will be considered
  20368.                          as ordinary printable text.
  20369.                      -n  Control characters other than Tab,
  20370.                          CarriageReturn and NewLine will be
  20371.                          considered to be string terminators just
  20372.                          like the null character.
  20373.                      -q  Quiet mode.  Don't announce the name of each
  20374.                          file as it's read.
  20375.                      -v  Verbose.  Paste the name of the file in
  20376.                          which it occurs onto the front of each
  20377.                          string.
  20378.                      -l  Long mode.  Show where each string occurs,
  20379.                          counting bytes from the beginning of the
  20380.                          file.  The radix used can be explicitly
  20381.  
  20382.  
  20383.  
  20384.                                      Page 322
  20385.  
  20386.                                                                          Help
  20387.  
  20388.  
  20389.                          chosen with -o, -d, -x, or -r; it defaults
  20390.                          to the value specified by the RADIX
  20391.                          environmental variable if defined or 16
  20392.                          otherwise.
  20393.                      -o  Octal offsets.
  20394.                      -d  Decimal offsets.
  20395.                      -x  Hex offsets shown.
  20396.                      -r<radix>  User-specified radix.
  20397.                      --  End of options.
  20398.  
  20399.  
  20400.             sum:      Checksum the contents of a file
  20401.  
  20402.                  Usage:  sum [-rxh-] [ file1 file2 ... ]
  20403.  
  20404.                     sum checksums  the contents  of each of the files
  20405.                     you specify,  writing the results to stdout along
  20406.                     with a  count of the number of 512-byte blocks it
  20407.                     read (including any partial blocks.)  If no files
  20408.                     are  given,   sum  reads  from  stdin.    sum  is
  20409.                     typically used  to validate  a file  communicated
  20410.                     over a possibly noisy communications line.
  20411.  
  20412.                     sum treats  the  characters  it  reads  as  8-bit
  20413.                     unsigned integers  and normally  just  adds  them
  20414.                     together  to   form  a  16-bit  unsigned  result.
  20415.                     Overflows are ignored.
  20416.  
  20417.                  Options:
  20418.  
  20419.                      -r  Rotated checksum.  Rotate the accumulated
  20420.                          checksum right one bit position before
  20421.                          adding each character.
  20422.                      -x  Xor'ed checksum.  For each new character, c,
  20423.                          the checksum, i, is calculated as
  20424.                          i += (i << 1) ^ c.
  20425.                      -h  Help.  (This screen.)
  20426.                      --  End of options.
  20427.                      
  20428.                     (The default  and rotated  checksums are the same
  20429.                     as those  calculated by  the UNIX  System  V  sum
  20430.                     command; the  xor  checksum  is  unique  to  this
  20431.                     implementation.)
  20432.  
  20433.  
  20434.  
  20435.  
  20436.  
  20437.  
  20438.  
  20439.  
  20440.  
  20441.  
  20442.  
  20443.  
  20444.  
  20445.  
  20446.                                      Page 323
  20447.  
  20448.      Help
  20449.  
  20450.  
  20451.             tabs:     Expand/Unexpand Tabs
  20452.  
  20453.                  Usage:  tabs [-hua-] [-<tabs>][ file1 file2 ... ]
  20454.  
  20455.                     tabs expands tab characters into spaces or, if -u
  20456.                     is specified,  unexpands spaces  into tabs  as it
  20457.                     copies the  input files  to stdout.   If no files
  20458.                     are given,  tabs reads  from stdin.   If multiple
  20459.                     files are  given, they're  concatenated one after
  20460.                     the other to stdout.
  20461.  
  20462.                     When unexpanding,  only leading  white  space  is
  20463.                     normally converted  to tabs.  If -a is specified,
  20464.                     tabs are inserted anywhere they would replace two
  20465.                     or more characters.
  20466.  
  20467.                  Options:
  20468.  
  20469.                      -h  Help.  (This screen.)
  20470.                      -u  Unexpand tabs.
  20471.                      -a  Unexpand all tabs.
  20472.                      -<tabs>    Tab settings to use for viewing text.
  20473.                                 Default is to use value given by the
  20474.                                 TABS environment variable or, if
  20475.                                 that's undefined, to assume tabstops
  20476.                                 every 8 characters.  If desired, a
  20477.                                 list of tabstops can specified,
  20478.                                 separated by commas; the difference
  20479.                                 between the last two tabs given is
  20480.                                 used a standard increment for
  20481.                                 following tabs.
  20482.                      --  End of options.
  20483.  
  20484.  
  20485.  
  20486.  
  20487.  
  20488.  
  20489.  
  20490.  
  20491.  
  20492.  
  20493.  
  20494.  
  20495.  
  20496.  
  20497.  
  20498.  
  20499.  
  20500.  
  20501.  
  20502.  
  20503.  
  20504.  
  20505.  
  20506.  
  20507.  
  20508.                                      Page 324
  20509.  
  20510.                                                                          Help
  20511.  
  20512.  
  20513.             tail:     Copy the last few lines or bytes of a file to
  20514.             Stdout
  20515.  
  20516.                  Usage:  tail [-hcfnq-] [-i<sec>] [m<msec>]
  20517.                  [-+<start>]
  20518.                            [-t<tabs>] [ file1 file2 ... ]
  20519.  
  20520.                     tail copies the last part of the file you specify
  20521.                     onto stdout.   You  may specify  where  to  begin
  20522.                     copying in  either lines  or bytes  measured from
  20523.                     either the  beginning or the end of the file.  If
  20524.                     no file  is given,  tail  reads  from  stdin.  If
  20525.                     several files are given, each is announced unless
  20526.                     you specify quiet mode.
  20527.  
  20528.                  Options:
  20529.  
  20530.                      -h  Help.  (This screen.)
  20531.                      -c  Count characters.  (Default is lines.)
  20532.                      -f  Follow.  At end of file, go into an endless
  20533.                          loop, sleeping for a second, then waking up
  20534.                          to see if more data's been added.  (Use ^C
  20535.                          to exit.)  The follow option is not valid if
  20536.                          more than one file is specified and is
  20537.                          ignored if data is being read from a pipe.
  20538.                      -i<sec>    Interval in seconds between checking
  20539.                                 for more data if -f option is used.
  20540.                                 (If the interval specified is greater
  20541.                                 than one second, tail will
  20542.                                 temporarily drop back to a one second
  20543.                                 interval anytime it finds new data
  20544.                                 when it does wake up.)
  20545.                      -m<msec>   Interval in milliseconds between
  20546.                                 checking for more data if -f option
  20547.                                 is used.
  20548.                      -<start>   Starting point, relative to the end
  20549.                                 of the file.  (Default is last 10
  20550.                                 lines or 512 bytes.)
  20551.                      +<start>   Starting point, relative to the start
  20552.                                 of the file.
  20553.                      -t<tabs>   Tab settings to use for viewing text.
  20554.                                 (Default is to use value given by the
  20555.                                 TABS environment variable or, if
  20556.                                 that's undefined, to do no tab
  20557.                                 expansion.)
  20558.                      -n  No tab expansion.
  20559.                      -q  Quiet mode.  Don't announce the name of each
  20560.                          file it's read.
  20561.                      --  End of options.
  20562.  
  20563.  
  20564.  
  20565.  
  20566.  
  20567.  
  20568.  
  20569.  
  20570.                                      Page 325
  20571.  
  20572.      Help
  20573.  
  20574.  
  20575.             tar:  Read/Write UNIX TAR and CPIO Format Files
  20576.  
  20577.                  Usage:  tar [-acCtMxXh FLvpPqs!rRfQWZ-] [-d dir] [-m
  20578.                  map]
  20579.                            [-g hours] [-G hours] [-O offset] [-E
  20580.                  endset] [-b sex]
  20581.                            [-B blksize] [ tarfile ] [ file1 file2 ...
  20582.                  ]
  20583.  
  20584.                     tar is  used to  read or  write a  simple archive
  20585.                     format  popular   for  exchanging  files  between
  20586.                     dissimilar machines.
  20587.  
  20588.                     tar normally  expects the archive to be in a file
  20589.                     specified by  the tarfile  operand.  When listing
  20590.                     or extracting  files, the  file names that follow
  20591.                     are considered  to be in the name space of what's
  20592.                     in the  archive; wildcards  should not  be  used.
  20593.                     When adding  files, the  names are  in the user's
  20594.                     normal file name space.
  20595.  
  20596.                     When  reading   an  archive,   this  tar  program
  20597.                     automatically detects  whether it  was written in
  20598.                     CPIO or TAR format and what bytesex was used.
  20599.  
  20600.                     When  extracting   files,  this  version  of  tar
  20601.                     incorporates logic  to interactively  crunch up a
  20602.                     filename in  the archive  into something legal on
  20603.                     an OS/2 or NT filesystem.  If -F is specified (or
  20604.                     you're using  OS/2 1.1),  FAT  naming  rules  are
  20605.                     enforced.   Otherwise, HPFS  or  NTFS  rules  are
  20606.                     assumed, meaning long filenames are assumed to be
  20607.                     legal. Any  renamings will  be listed  in a  .map
  20608.                     file.      tar   also   incorporates   logic   to
  20609.                     automatically convert between the \n line endings
  20610.                     used in an archive and the \r\n line endings used
  20611.                     under OS/2  or NT  unless the  file appears to be
  20612.                     binary.
  20613.  
  20614.                  Basic Commands:
  20615.  
  20616.                      -a  Add files to the end of the archive.
  20617.                      -c  Copy the specified files in the archive to
  20618.                          stdout.
  20619.                      -C  Copy entire archive segments (including
  20620.                          headers and any padding) to stdout.  After
  20621.                          the last segment, write a trailer to mark
  20622.                          the end of the archive.  (If you intend to
  20623.                          concatenate archives, use the -Z option to
  20624.                          suppress writing the trailer.)
  20625.                      -t  List the contents of the archive.  This is
  20626.                          the default.
  20627.  
  20628.  
  20629.  
  20630.  
  20631.  
  20632.                                      Page 326
  20633.  
  20634.                                                                          Help
  20635.  
  20636.  
  20637.                      -M  Just build a mapfile for renaming files in
  20638.                          the archive to OS/2 or NT conventions; don't
  20639.                          extract anything.
  20640.                      -x  Extract files from the archive.  Default is
  20641.                          all files in the archive.  (Do not use
  20642.                          wildcarding.)
  20643.                      -X  Extract everything EXCEPT the specified
  20644.                          files from the archive.
  20645.                      -h  Help.  (This screen.)
  20646.                      
  20647.  
  20648.  
  20649.  
  20650.  
  20651.  
  20652.  
  20653.  
  20654.  
  20655.  
  20656.  
  20657.  
  20658.  
  20659.  
  20660.  
  20661.  
  20662.  
  20663.  
  20664.  
  20665.  
  20666.  
  20667.  
  20668.  
  20669.  
  20670.  
  20671.  
  20672.  
  20673.  
  20674.  
  20675.  
  20676.  
  20677.  
  20678.  
  20679.  
  20680.  
  20681.  
  20682.  
  20683.  
  20684.  
  20685.  
  20686.  
  20687.  
  20688.  
  20689.  
  20690.  
  20691.  
  20692.  
  20693.  
  20694.                                      Page 327
  20695.  
  20696.      Help
  20697.  
  20698.  
  20699.                  Basic Options:
  20700.  
  20701.                      -F  FAT filesystem naming.  (Automatically
  20702.                          chosen if the OS/2 release level < 1.2.)
  20703.                      -B blksize Use specified blocksize for all i/o
  20704.                                 to/from the archive.  Default is 4096
  20705.                                 bytes for disk files; for tape
  20706.                                 devices, the default is the device
  20707.                                 default.
  20708.                      -L  Long listing similar to ls -L showing the
  20709.                          attributes, timestamp and length of each
  20710.                          file in the archive.
  20711.                      -v  Verbose.  Like -L, but also show the offset
  20712.                          of each file from the beginning of the
  20713.                          archive.
  20714.                      -p  CPIO format, using binary headers.
  20715.                      -P  CPIO format, using ASCII headers.
  20716.                      -q  Quiet.  tar normally prints the header of
  20717.                          each file as it's extracted (-x) or added (-
  20718.                          a) to the archive.  This option turns that
  20719.                          off.
  20720.                      -s  Read the archive from stdin when listing
  20721.                          table of contents or extracting.  Write the
  20722.                          archive to stdout when adding files.
  20723.                          (Implies non-interactive.)
  20724.                      -!  Non-interactive.  Files are renamed as
  20725.                          necessary for OS/2 or NT conventions.
  20726.                          (Particularly useful with -M when trying to
  20727.                          read a new, large archive file.)
  20728.                      -r  CarriageReturn/NewLine expansion is turned
  20729.                          off. (Default is normally to convert between
  20730.                          \n in the archive and \r\n under OS/2 or NT
  20731.                          unless the file appears to be binary.)
  20732.                      -R  CarriageReturn/NewLine expansion is forced
  20733.                          ON, even for files that appear to be binary.
  20734.                      --  End of options.
  20735.                      
  20736.                  Advanced Options:
  20737.  
  20738.                      -d dir     Default destination drive and
  20739.                                 directory when extracting files.
  20740.                      -m map     Specific filename to be used for
  20741.                                 showing mappings from names in the
  20742.                                 archive to names used on OS/2 or NT.
  20743.                                 (Default is to paste a .map extension
  20744.                                 onto the name of the tar file; if -s
  20745.                                 is specified, no map file is used
  20746.                                 unless -m is given.)
  20747.                      -f         Fullpath option.  Put the full
  20748.                                 pathname (minus any disk prefix)
  20749.                                 specified on the command line into
  20750.                                 the archive header when adding.  (In
  20751.                                 this context, the full path means the
  20752.                                 full name given on the command line,
  20753.  
  20754.  
  20755.  
  20756.                                      Page 328
  20757.  
  20758.                                                                          Help
  20759.  
  20760.  
  20761.                                 not the fully-qualified name starting
  20762.                                 from the root directory.)  When
  20763.                                 extracting, use the full pathname
  20764.                                 given in the header to determine
  20765.                                 where the files will go.
  20766.                      -ff        Another variation on the fullpath
  20767.                                 option that will put the entire
  20768.                                 pathname, even including the drive
  20769.                                 letter into the tar archive.  The
  20770.                                 resulting name isn't really legal in
  20771.                                 a tar file, but it's useful for doing
  20772.                                 backups of several drives at once.
  20773.                      -g hours   The number of hours GMT is ahead of
  20774.                                 the local zone, e.g., 5 hours in New
  20775.                                 York or 8 hours in California. U.S.
  20776.                                 daylight savings is assumed in the
  20777.                                 summer months.  (OS/2 only.)
  20778.                      -G hours   Same as -g, but without daylight
  20779.                                 savings adjustments. (Under OS/2, if
  20780.                                 neither -g nor -G is specified, tar
  20781.                                 looks for a TZ variable in the
  20782.                                 environment; if it's not defined, tar
  20783.                                 ignores the difference between local
  20784.                                 time and GMT used in the archive.
  20785.                                 Under Windows NT, the -g and -G
  20786.                                 options and the TZ variable are
  20787.                                 unnecessary since the system keeps
  20788.                                 track of the difference between local
  20789.                                 time and GMT.)
  20790.                      -O offset  Offset at which to start reading the
  20791.                                 archive file. Given in bytes from
  20792.                                 beginning of the file.
  20793.                      -E endset  Offset at which to stop reading the
  20794.                                 archive file.
  20795.                      -b sex     Byte sex in the archive:  abcd, badc,
  20796.                                 cdab or dcba.  (Default is to autosex
  20797.                                 bytesex in existing archives and to
  20798.                                 use abcd in new archives.)
  20799.                      -Q         Very Quiet.  tar normally warns of
  20800.                                 any garbled sections that it skipped;
  20801.                                 this turns off those warnings also.
  20802.                      -W         Warnings.  Show just the files that
  20803.                                 can't be extracted to OS/2 or NT
  20804.                                 because of their file types. (Always
  20805.                                 shown in bright red.)
  20806.                      -Z         Suppress writing the trailer normally
  20807.                                 written following the last segment
  20808.                                 extracted from an archive with the -C
  20809.                                 option.  (Useful for concatenating
  20810.                                 segments extracted from several
  20811.                                 separate archives.)
  20812.                      
  20813.                  TAR Format:
  20814.  
  20815.  
  20816.  
  20817.  
  20818.                                      Page 329
  20819.  
  20820.      Help
  20821.  
  20822.  
  20823.                     Tar files  are organized  as a series of 512-byte
  20824.                     blocks. Individual  files always start on a block
  20825.                     boundary with  a header  block  followed  by  the
  20826.                     uncompressed data in the file.  At the end of the
  20827.                     file are  two blocks  filled with  binary  zeros.
  20828.                     The header has the following format:
  20829.  
  20830.                         typedef struct {
  20831.                               char  name[100],
  20832.                                     mode[8],
  20833.                                     userid[8],
  20834.                                     groupid[8],
  20835.                                     filesize[12],
  20836.                                     timestamp[12],
  20837.                                     checksum[8],
  20838.                                     linkflag,
  20839.                                     linkname[100];
  20840.                                     unused_chars[255];
  20841.                               } header;
  20842.  
  20843.                     Everything is  in ascii  with nulls and spaces to
  20844.                     punctuate the  fields.   Numbers  are  always  in
  20845.                     octal.   The mode,  user  and  group  ids  aren't
  20846.                     meaningful on  OS/2 and  NT and  are ignored when
  20847.                     extracting and just filled in with read/write for
  20848.                     owner, owned  by root when adding.  The timestamp
  20849.                     is in seconds since Jan 1 00:00:00 GMT 1970.  The
  20850.                     checksum is  calculated as if the field contained
  20851.                     spaces.    The  linkflag  tells  the  file  type,
  20852.                     reported in  the  long  listing  as  one  of  the
  20853.                     following:
  20854.  
  20855.                      -   Normal File
  20856.                      D   Directory
  20857.                      L   Link (not a separate file, just another name
  20858.                          for one that already exists)
  20859.                      S   Symbolic Link
  20860.                      C   Character Device
  20861.                      B   Block Device
  20862.                      F   FIFO
  20863.                      
  20864.                     Under OS/2  and NT,  only the  normal  files  and
  20865.                     directories have  any meaning.   Directories  are
  20866.                     highlighted.   The other  file types are reported
  20867.                     in bright red but otherwise ignored.
  20868.  
  20869.                  CPIO Format:
  20870.  
  20871.                     If -p  is specified, tar will read and write cpio
  20872.                     format  files,   using  binary   headers  of  the
  20873.                     following format:
  20874.  
  20875.                         typedef struct {
  20876.                               short  magic,     /* Always 0x71c7 ==
  20877.  
  20878.  
  20879.  
  20880.                                      Page 330
  20881.  
  20882.                                                                          Help
  20883.  
  20884.  
  20885.                                                    Octal 070707 */
  20886.                                      dev;       /* Device containing
  20887.                         directory
  20888.                                                    entry for this
  20889.                         file. */
  20890.                               ushort inode,     /* UNIX inode number.
  20891.                         */
  20892.                                      mode,
  20893.                                      userid,
  20894.                                      groupid,
  20895.                                      nlink,
  20896.                                      rdev;      /* Device ID for
  20897.                         special
  20898.                                                    files. */
  20899.                               ulong  timestamp;
  20900.                               ushort namelen;   /* including trailing
  20901.                         null. */
  20902.                               ulong  filesize;
  20903.                               char   name[ namelen rounded to word ];
  20904.                               } cpio_header;
  20905.  
  20906.             
  20907.                     The dev,  inode, mode, userid, groupid, nlink and
  20908.                     rdev fields  are not  meaningful on  NT  and  are
  20909.                     ignored when  extracting and  filled in  with  0,
  20910.                     read/write by owner, 0, 0, 1 and 0, respectively,
  20911.                     when writing.
  20912.  
  20913.                     If -P  is specified, tar will read and write cpio
  20914.                     format files  using the  alternate  ASCII  format
  20915.                     headers, where  each ushort  is written  as a  6-
  20916.                     character octal  number, each  ulong  as  an  11-
  20917.                     character  octal   number,  and   name  is  null-
  20918.                     terminated.
  20919.  
  20920.                     In a  cpio file,  data  immediately  follows  the
  20921.                     header and is not padded to a block boundary.
  20922.  
  20923.                  Colors:
  20924.  
  20925.                     You may  set your  own choices  for screen colors
  20926.                     using these environmental variables:
  20927.  
  20928.                     Name          Use                    Default
  20929.  
  20930.                     COLORS        Normal screen colors   White on
  20931.                     Black
  20932.                     DIRECTORIES   Directories            Bright
  20933.                     FOREIGNFILES  Filetypes not supported     Bright
  20934.                     Red
  20935.                                    by OS/2 and NT
  20936.  
  20937.                     Colors recognized  are black, red, green, yellow,
  20938.                     blue, magenta (or red blue), cyan (or blue green)
  20939.  
  20940.  
  20941.  
  20942.                                      Page 331
  20943.  
  20944.      Help
  20945.  
  20946.  
  20947.                     or white.   Foreground  colors may also be bright
  20948.                     or blink.   The names of the colors and the words
  20949.                     bright, blink  and on  may be  in either upper or
  20950.                     lower  or   mixed  case  but  the  names  of  the
  20951.                     environmental variables  themselves must  be  all
  20952.                     upper case.
  20953.  
  20954.                     Either or  both  the  foreground  and  background
  20955.                     colors may  be specified;  if you don't specify a
  20956.                     value, it's  considered transparent  and inherits
  20957.                     the  color   underneath  it.     DIRECTORIES  and
  20958.                     FOREIGNFILES inherit from COLORS.
  20959.  
  20960.  
  20961.  
  20962.             tee:      Copy Stdin to Stdout and to Each File Specified
  20963.  
  20964.                  Usage:  tee [ -a- ] file1 [ file2 ... ]
  20965.  
  20966.                     tee   is    a   ``pipe-fitting''    utility   for
  20967.                     snapshotting the  data passing through the middle
  20968.                     of a pipeline.
  20969.  
  20970.                  Options:
  20971.  
  20972.                      -a  Append to any output files that already
  20973.                          exist instead of truncating and overwriting
  20974.                          them.
  20975.                      -h  Help.
  20976.                      --  End of Options.
  20977.  
  20978.  
  20979.             touch:    Create File or Set Modification Time
  20980.  
  20981.                  Usage:  touch [-rfc-] [ mmddhhmm[yy] ] pathname1 [
  20982.                  pathname2 ... ]
  20983.  
  20984.                     touch sets the timestamp on a file to the current
  20985.                     or specified  date and time.  If the file doesn't
  20986.                     exist, the normal action is to create it.
  20987.  
  20988.                     The OS/2  1.1 kernel ignores attempts to change a
  20989.                     directory timestamp.
  20990.  
  20991.                  Options:
  20992.  
  20993.                      mmddhhmmyy      Month, Day, Hour, Minutes and
  20994.                                      Year in decimal.
  20995.                      -r  Recursively touch contents of directories.
  20996.                      -f  Force Read-only files to be touched also.
  20997.                      -c  File is Not created if it doesn't already
  20998.                          exist.
  20999.                      -h  Help.
  21000.                      --  End of options.
  21001.  
  21002.  
  21003.  
  21004.                                      Page 332
  21005.  
  21006.                                                                          Help
  21007.  
  21008.  
  21009.             tr:  Translate Characters Filter
  21010.  
  21011.                  Usage:  tr [-cdsnh-] [ string1 [string2] ]
  21012.  
  21013.                     tr  is   used   to   perform   simple   character
  21014.                     substitutions as  it copies  data from  stdin  to
  21015.                     stdout.   Individual characters  in  string1  are
  21016.                     mapped  to   the  corresponding   characters   of
  21017.                     string2. If string2 is too short, it is padded by
  21018.                     duplicating  its   last  character.    In  either
  21019.                     string, the  minus sign can be used to indicate a
  21020.                     range of characters.
  21021.  
  21022.                     Here's an  example which   creates  a list of all
  21023.                     the words in file1, one per line, in file2, where
  21024.                     a  word   is  taken   as  a   maximal  string  of
  21025.                     alphabetics.   (The ^n  character is  expanded by
  21026.                     the C shell into a newline character.)
  21027.  
  21028.                         % tr -csn A-Za-z ^n <file1 >file2
  21029.  
  21030.                  Options:
  21031.  
  21032.                      -h  Help.  (This screen.)
  21033.                      -c  Complement the set of characters in string1.
  21034.                      -d  Delete any occurrences of the characters in
  21035.                          string1.  (If present, string2 is ignored.)
  21036.                      -s  Squeeze all strings of repeated output
  21037.                          characters in string2 to single characters.
  21038.                      -n  Normalize line endings.  Ensure that every
  21039.                          line ends with \r\n.  Fixup any \r or \n by
  21040.                          itself or any reversed \n\r character pair.
  21041.                          When squeezing, normalization also causes
  21042.                          repeated \r\n sequences to be squeezed if
  21043.                          either \r or \n is in string2.
  21044.                      --  End of options.
  21045.  
  21046.  
  21047.  
  21048.  
  21049.  
  21050.  
  21051.  
  21052.  
  21053.  
  21054.  
  21055.  
  21056.  
  21057.  
  21058.  
  21059.  
  21060.  
  21061.  
  21062.  
  21063.  
  21064.  
  21065.  
  21066.                                      Page 333
  21067.  
  21068.      Help
  21069.  
  21070.  
  21071.             unhash:   Turn off Path Hashing
  21072.  
  21073.                  Usage:  unhash [-h-]
  21074.  
  21075.                     Normally, a  hashing  mechanism  is  used  in  an
  21076.                     attempt  to   speed  up   searches  of  the  path
  21077.                     directories.     If  you're   performing   system
  21078.                     administration work,  moving files  in  the  path
  21079.                     directories, the  hash mechanism  may not  always
  21080.                     reflect the  latest changes  you've  made.    The
  21081.                     unhash command  can be  used to turn hashing off,
  21082.                     setting nohashing = 1.
  21083.  
  21084.                     (See also the rehash and hashstat commands.)
  21085.  
  21086.                  Options:
  21087.  
  21088.                      -h  Help.
  21089.                      --  End of options.
  21090.  
  21091.  
  21092.  
  21093.  
  21094.  
  21095.  
  21096.  
  21097.  
  21098.  
  21099.  
  21100.  
  21101.  
  21102.  
  21103.  
  21104.  
  21105.  
  21106.  
  21107.  
  21108.  
  21109.  
  21110.  
  21111.  
  21112.  
  21113.  
  21114.  
  21115.  
  21116.  
  21117.  
  21118.  
  21119.  
  21120.  
  21121.  
  21122.  
  21123.  
  21124.  
  21125.  
  21126.  
  21127.  
  21128.                                      Page 334
  21129.  
  21130.                                                                          Help
  21131.  
  21132.  
  21133.             uniq:     Report unique lines in text files
  21134.  
  21135.                  Usage:  uniq [-hbcdiuw-] [ file1 file2 ...]
  21136.  
  21137.                     uniq does  a quick,  simple string  comparison of
  21138.                     adjacent  lines  in  text  files,  normally  just
  21139.                     discarding any  duplicates as it copies its input
  21140.                     to stdout.
  21141.  
  21142.                     There are  some diff-style  options for  ignoring
  21143.                     upper-/lower-case differences  or treating  white
  21144.                     spaces of  any length  as equal,  etc.  Also, you
  21145.                     can optionally choose to list only the lines that
  21146.                     occur  just   once  or   only  those   that  have
  21147.                     duplicates.
  21148.  
  21149.                     If several  files are  given, the  effect is  the
  21150.                     same as  if they  were pasted together, one right
  21151.                     after another into one long file.
  21152.  
  21153.                  Options:
  21154.  
  21155.                      -h  Help.
  21156.                      -b  Blank spaces of any length compare equal.
  21157.                          Ignore any leading or trailing white space
  21158.                          on each line.
  21159.                      -c  Preface each line with a count of the number
  21160.                          of times it occurred.
  21161.                      -d  Duplicates.  Only the lines which have at
  21162.                          least one duplicate are reported.
  21163.                      -i  Ignore character case.
  21164.                      -u  Unique lines.  Only the lines which occur
  21165.                          only once are reported.
  21166.                      -w  White space is ignored totally.
  21167.                      --  End of options.
  21168.  
  21169.  
  21170.             verify:   Turn Write Verification Mode On or Off
  21171.  
  21172.                  Usage:  verify [-h-] [ mode ]
  21173.  
  21174.                     When verification  mode is  turned on, the system
  21175.                     will always  verify that  any data  written to  a
  21176.                     disk can be read back.  The mode can be specified
  21177.                     as 0  or off,  the default,  or 1  or on.   If no
  21178.                     arguments are  given, verify  simply reports  the
  21179.                     current mode.  Under NT, verify is always on.
  21180.  
  21181.                  Options:
  21182.  
  21183.                      -h  Help.
  21184.                      --  End of options.
  21185.  
  21186.  
  21187.  
  21188.  
  21189.  
  21190.                                      Page 335
  21191.  
  21192.      Help
  21193.  
  21194.  
  21195.             vol:      List Volume Labels
  21196.  
  21197.                  Usage:  vol [-ach] [ disk1 disk2 ... ]
  21198.  
  21199.                     vol reports  the volume label information on each
  21200.                     of  the   specified  disks.    If  no  disks  are
  21201.                     specified,   vol    looks   for    a    DRIVEMASK
  21202.                     environmental variable  that can  be used to mask
  21203.                     off just  the  drive  you  want  reported.    The
  21204.                     DRIVEMASK  is   specified  as  a  list  of  drive
  21205.                     letters; ranges  are allowed.  Otherwise, all the
  21206.                     partitions beginning  with c:  are reported.  The
  21207.                     current disk's label information is highlighted.
  21208.  
  21209.                     This command  is  normally  stored  in  the  file
  21210.                     vl.exe and invoked via an alias so it can be used
  21211.                     from cmd.exe  without colliding with the internal
  21212.                     cmd.exe vol function.
  21213.  
  21214.                  Options:
  21215.  
  21216.                      -a  If no disks are specified, report on all
  21217.                          disks.
  21218.                      -c  If no disks are specified, report on just
  21219.                          the current disk.
  21220.                      -h  Help.
  21221.                      --  End of options.
  21222.                  Colors:
  21223.  
  21224.                     You may  set your  own choices  for screen colors
  21225.                     using these environmental variables:
  21226.  
  21227.                     Name          Use                    Default
  21228.  
  21229.                     COLORS        Normal screen colors   White on
  21230.                     Black
  21231.                     HIGHLIGHT     Current disk           Bright
  21232.  
  21233.                     Colors recognized  are black, red, green, yellow,
  21234.                     blue, magenta (or red blue), cyan (or blue green)
  21235.                     or white.   Foreground  colors may also be bright
  21236.                     or blink.   The names of the colors and the words
  21237.                     bright, blink  and on  may be  in either upper or
  21238.                     lower  or   mixed  case  but  the  names  of  the
  21239.                     environmental variables  themselves must  be  all
  21240.                     upper case.
  21241.  
  21242.                     Either or  both  the  foreground  and  background
  21243.                     colors may  be specified;  if you don't specify a
  21244.                     value, it's  considered transparent  and inherits
  21245.                     the color underneath it.  HIGHLIGHT inherits from
  21246.                     COLORS.
  21247.  
  21248.  
  21249.  
  21250.  
  21251.  
  21252.                                      Page 336
  21253.  
  21254.                                                                          Help
  21255.  
  21256.  
  21257.             wait:     Wait for Children to Complete
  21258.  
  21259.                  Usage:  wait [-h-]
  21260.  
  21261.                     Sleep until  a child  thread or process completes
  21262.                     or until an interrupt occurs.
  21263.  
  21264.                  Options:
  21265.  
  21266.                      -h  Help.
  21267.                      --  End of options.
  21268.  
  21269.  
  21270.             wc:       Count Words (and lines and characters)
  21271.  
  21272.                  Usage:  wc [ -lwr ] [ file1 file2 ... ]
  21273.  
  21274.                     wc prints  counts all  the  lines,  words  and/or
  21275.                     characters in  each of  the files  specified, and
  21276.                     totals for  the whole  list.   If  no  files  are
  21277.                     specified, it counts stdin.
  21278.  
  21279.                  Options:
  21280.  
  21281.                      -l  Count lines
  21282.                      -w  Count words
  21283.                      -c  Count characters
  21284.                      -h  Help.
  21285.                      --  End of options.
  21286.  
  21287.                     The default is -lwc.
  21288.  
  21289.  
  21290.             whereis:  Find where executable files are located
  21291.  
  21292.                  Usage:  whereis command
  21293.  
  21294.                     whereis is a self-loading procedure that searches
  21295.                     all the  directories on  the path,  looking for a
  21296.                     .csh, .exe,  .com, or  .cmd file corresponding to
  21297.                     the  command  specified.    All  occurrences  are
  21298.                     printed.
  21299.  
  21300.  
  21301.  
  21302.  
  21303.  
  21304.  
  21305.  
  21306.  
  21307.  
  21308.  
  21309.  
  21310.  
  21311.  
  21312.  
  21313.  
  21314.                                      Page 337
  21315.  
  21316.      Help
  21317.  
  21318.  
  21319.             xd:       Hex dump a file to Stdout
  21320.  
  21321.                  Usage:  xd [-hbwlFD Zdxor nNq-] [-r<radix>]
  21322.                            [-O <offset>] [-E <endset>]
  21323.                            [-L[<items>]] [ file1 file2 ... ]
  21324.  
  21325.                     xd dumps  its input, presumed to be in binary, in
  21326.                     variety of  formats, the  default being  hex.  If
  21327.                     more than  one file  is given,  each is dumped in
  21328.                     sequence.   If no  files are  specified, xd reads
  21329.                     from stdin.   Sequences  of lines  containing the
  21330.                     same data  are collapsed  out and  replaced by an
  21331.                     asterisk.
  21332.  
  21333.                  Options:
  21334.  
  21335.                      -h  Help.  (This screen.)
  21336.                      
  21337.                  Basic display formats:
  21338.  
  21339.                      -b  Bytes.  (Default.)
  21340.                      -w  16-bit words.
  21341.                      -l  32-bit long words.
  21342.                      -F  Short 4-byte floating point.  Floating point
  21343.                          values are always displayed in decimal.
  21344.                      -D  Double-precision 8-byte floating point.
  21345.                      -Z  Suppress leading zeros.  Normally, leading
  21346.                          zeros are shown except when displaying in
  21347.                          decimal.
  21348.                      
  21349.                  Radix to be used for offsets and data:
  21350.  
  21351.                      -d  Decimal (unsigned).
  21352.                      -x  Hex.
  21353.                      -o  Octal.
  21354.                       -r<radix> User-specified radix.  If a radix < 8
  21355.                                 is chosen, offsets are always shown
  21356.                                 in hex.
  21357.                      
  21358.                  Other options:
  21359.  
  21360.                      -O <offset>     Offset at which to begin
  21361.                                 dumping.
  21362.                      -E <endset>     Offset at which to stop dumping.
  21363.                      -L[<items>]     Number of items (bytes, words,
  21364.                                 etc.) to dump.  If -L is specified,
  21365.                                 the default is one.
  21366.                      -n  No ascii column.
  21367.                      -N  No offset column.
  21368.                      -q  Quiet mode.  Don't announce the name of each
  21369.                          file as it's read.
  21370.                      -v  Verbose.  Show lines of repeated data.
  21371.                      --  End of options.
  21372.             
  21373.  
  21374.  
  21375.  
  21376.                                      Page 338
  21377.